Skip to content

Instantly share code, notes, and snippets.

@khanghoang
Last active November 10, 2015 10:11
Show Gist options
  • Save khanghoang/f677fda9cffff730f34d to your computer and use it in GitHub Desktop.
Save khanghoang/f677fda9cffff730f34d to your computer and use it in GitHub Desktop.
ES6 features

##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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment