ES6 中的 typeof(Symbol()) 是什么?

What is the typeof(Symbol()) in ES6?

所以,我们都有console line,我们可以调试其中的typeof(Symbol())。但是我们得到的是 symbol。正如我们所知,我们在 JS 中有几种类型的数据:

string, boolean, number - 原语;

undefined - 特殊未分级;

null - 对象(对象的特殊子类);

object - 对象;

function - 函数(对象的特殊子类)。

那么,JS 中这些类型中的哪一组对应于 Symbols,为什么?

网络上的一些答案说,它有一个原始的行为,但没有解释为什么...

"symbol" 数据类型本身就是原始类型。您会在下面看到它。

https://developer.mozilla.org/en-US/docs/Glossary/Primitive

ECMAScript 2015 定义 a Symbol as its own kind of primitive:

4.3.25 Symbol value

primitive value that represents a unique, non-String Object property key

将此语言与规范对字符串和数字类型的定义进行比较,您会发现它是规范定义原始类型的标准方式:

4.3.17 String value
primitive value that is a finite ordered sequence of zero or more 16-bit unsigned integer

4.3.20 Number value
primitive value corresponding to a double-precision 64-bit binary format IEEE 754-2008 value