Javascript - Symbol

About

A symbol is a unique and immutable data type.

New in ES6.

Usage:

  • Identifier for object properties.

Syntax

Symbol([description])

Properties

  • Type: Symbol
console.log ( typeof Symbol() === 'symbol' );
  • Description
console.log ( Symbol('myDescription').toString()  );

Example

// Creation of three new symbols. 
// Symbol("foo") does not coerce the string "foo" into a symbol. 
// It creates a new symbol each time
var sym1 = Symbol();
var sym2 = Symbol("foo");
var sym3 = Symbol("foo");

// false
var symFooEqual = (sym2  === sym3)
console.log("sym2 = sym3 ? " + symFooEqual.toString() ); 

Documentation / Reference





Discover More
Javascript - Primitive Data Type

Javascript has 6 primitive data type. string number boolean null undefined symbol Except for null and undefined, all primitive values have object equivalents that wrap around the primitive...
Javascript - Type

Type in Javascript Javascript is not static typed but it exist Javascript wrapper language that implements it. See Only values have types in JavaScript; variables are just simple containers for those...



Share this page:
Follow us:
Task Runner