JS: Symbol.prototype

By Xah Lee. Date: . Last updated: .

New in ES2015.

Symbol.prototype is the value of the property key "prototype" of the function Symbol.

[see JS: Symbol Object]

console.log( Symbol.hasOwnProperty ( "prototype" ) ); // true

Type

Type of Symbol.prototype is object.

[see JS: Object Type]

console.log ( typeof Symbol.prototype === "object" ); // true

console.log ( Object.prototype.toString.call( Symbol.prototype ) === "[object Symbol]" ) // true

Parent

Parent of Symbol.prototype is Object.prototype.

// parent of Symbol.prototype
console.log ( Reflect.getPrototypeOf ( Symbol.prototype ) === Object.prototype ); // true

Purpose

Symbol.prototype is the parent of all symbol objects.

let ss = Symbol();

console.log (
Reflect.getPrototypeOf ( Object(ss) ) === Symbol.prototype
); // true

// Object(ss) converts symbol primitive ss to a symbol object

[see JS: Prototype and Inheritance]

Properties

  1. Symbol.prototype.constructor
  2. Symbol.prototype.description
  3. Symbol.prototype.toString ( )
  4. Symbol.prototype.valueOf ( )
  5. Symbol.prototype [ Symbol.toPrimitive ] ( hint )
  6. Symbol.prototype [ Symbol.toStringTag ]

2017-02-10 following is work in progress.













Symbol.prototype.constructor

Symbol.prototype.constructor is a value property.

The value is the object Symbol.

console.log ( Symbol.prototype.constructor === Symbol ); // true

ECMAScript® 2016 Language Specification#sec-symbol.prototype.constructor

Symbol.prototype.description

Return the description of the symbol.

Symbol.prototype.toString ( )

return a string of the form:

"Symbol(description)"

const x = Symbol("xyz");
console.log ( x.toString ( ) === "Symbol(xyz)" ); // true

ECMAScript® 2016 Language Specification#sec-symbol.prototype.tostring

Symbol.prototype.valueOf ( )

ECMAScript® 2016 Language Specification#sec-symbol.prototype.valueof

Symbol.prototype [ Symbol.toPrimitive ] ( hint )

ECMAScript® 2016 Language Specification#sec-symbol.prototype-@@toprimitive

Symbol.prototype [ Symbol.toStringTag ]

ECMAScript® 2016 Language Specification#sec-symbol.prototype-@@tostringtag

JS Symbol

  1. Symbol Tutorial
Liket it? I spend 2 years writing this tutorial. Help me spread it. Tell your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Object Ref
  5. DOM Scripting
  6. SVG
  7. Blog