O'Reilly logo

JavaScript Recipes: A Problem-Solution Approach by Keith Cirkel, Russ Ferguson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Russ Ferguson and Keith Cirkel 2017
Russ Ferguson and Keith CirkelJavaScript Recipes10.1007/978-1-4302-6107-0_15

15. Working with Symbols

Russ Ferguson and Keith Cirkel2
(1)
Ocean, New Jersey, USA
(2)
London, UK
 

What Are the Advantages of Using Symbols ?

Problem

You want to know why and how to use symbols in a project.

Solution

Symbols give you the ability to create unique tokens that will never clash with other symbols. Similar to UUIDs (Universal Unique Identifiers) , symbols can be used on objects to make unique properties.

The Code

let mySym1 = Symbol('This is my first Symbol');
let mySym2 = Symbol(); //returns false
console.log(mySym1 == mySym2);
console.log(mySym1.toString()) //returns  Symbol(This is my first Symbol)
Listing 15-1.
Creating Symbols ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required