-
-
Save deepakgd/806bf3cac9018955c8d65603cb100fe6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************** | |
A symbol is a JavaScript Primitive data type | |
(Number, String, Boolean, null, undefined) | |
Every symbol value returned from Symbol() is unique. | |
A symbol value may be used as an identifier for object properties; this is the data type's only purpose. | |
**********************************/ | |
let log = console.log; | |
const s1 = Symbol(); | |
const s2 = Symbol(123); | |
const s3 = Symbol('steve'); | |
//log(s1); | |
//log(s2); | |
//log(s3); | |
//log(typeof s2); | |
//log(s3.toString() ); | |
//log( Symbol(42) == Symbol(42) ); | |
//log( Symbol(42) === Symbol(42) ); | |
// | |
//log( Symbol.for(123) === Symbol(123) ); | |
//log( Symbol.for(123) === Symbol.for(123) ); | |
//log( Symbol.keyFor(s2) ); | |
//let s5 = Symbol.for(555); | |
//log( Symbol.keyFor(s5) ); | |
// | |
//let obj = {}; | |
//obj['prop1'] = 'value1'; | |
//obj['prop2'] = 'value2'; | |
//obj[Symbol()] = 'value3'; | |
//obj[Symbol()] = 'value3'; | |
//obj[Symbol()] = 'value3'; | |
//obj[Symbol()] = 'value3'; | |
//obj['prop4'] = Symbol() ; | |
// | |
//for( let p in obj){ | |
// log(p, obj[p]); | |
//} | |
//log( JSON.stringify(obj) ); | |
let s4 = Symbol.for('fred'); | |
log(s4); //the symbol created with the key 'fred' | |
// | |
let k4 = Symbol.keyFor(s4); | |
log(k4); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment