##ES6 features
###Symbol
#####Another primary type
Among undefined
, Null
, Boolean
, Number
, String
, Object
#####To represent of concepts.
-
As property keys.
Example:javascript
const MY_KEY = Symbol(); let obj = {};obj[MY_KEY] = 123; console.log(obj[MY_KEY]); // 123
#####Prevent methods clashes, for example:
#####Invoke `Symbol` as constructor and coercing symbols to string cause the `TypeError`
_Q: Why it doens't allow me to create Symbol as `new Symbol()`?
A: This prevents authors from creating an explicit Symbol wrapper object instead of a new symbol value. Creating an explicit wrapper object around primitive data types is no longer supported starting with ECMAScript However, existing primitive wrapper objects like `new Boolean, new String, new Number` can still created for legacy reason._
####Symbols are primitives or objects?
They are like strings (primitive) in how they are used for:
* As representations of concepts.
* As property keys.
* Like object `Symbol("foo") === Symbol("foo"); // false`