Symbol

A Symbol is used to define unique, anonymous, non-enumerable members for an object. It provides an extra level of privacy for these 'private' members. (Refer to 8.6.6 for more information about how data encapsulation can be achieved with Symbols.)

We cannot include the 'new' keyword when defining a Symbol. Thus, we cannot create explicit Symbol wrappers directly. As we define a Symbol, we can also pass in an optional string argument that is a description used for debugging. The string cannot be used to access the Symbol.


RESETRUNFULL
<!DOCTYPE html><html><body><script>

var o={};var s = Symbol('x');                            // (‘x’ is an optional string used for debugging only)console.log(typeof s);              // symbolo[s] = 100; console.log(o[s]);  // 100var so = Object(s);   // (this creates the wrapper indirectly)console.log(typeof so); // objectconsole.log(so);  // Symbol {[[PrimitiveValue]]: Symbol(x)}console.log(o[so]);       // 100

</script></body><html>