Javascript - Symbol

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard

1 - About

A symbol is a unique and immutable data type.

New in ES6.

Usage:

  • Identifier for object properties.
Advertising

3 - Syntax

Symbol([description])

4 - Properties

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

5 - 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() ); 

6 - Documentation / Reference

Advertising
web/javascript/es/symbol.txt · Last modified: 2019/02/16 17:40 by gerardnico