Symbol is a primitive data type of JS along with string,number,bool,null and undef
which are used to identify object properties since none is equal to the other.
// get symbol by name
let sym = Symbol.for('hello');
let sym1 = Symbol.for('id');
// get name by symbol
console.log( Symbol.keyFor(sym) ); // hello
console.log( Symbol.keyFor(sym1) ); // id
for() Searches for existing symbols
keyFor() Returns a shared symbol key from the global symbol registry.
toSource() Returns a string containing the source of the Symbol object
toString() Returns a string containing the description of the Symbol
valueOf() Returns the primitive value of the Symbol object.
// two symbols with the same description
const value1 = Symbol('hello');
const value2 = Symbol('hello');
console.log(value1 === value2); // false
// get symbol by name
let sym = Symbol.for('hello');
let sym1 = Symbol.for('id');
// get name by symbol
console.log( Symbol.keyFor(sym) ); // hello
console.log( Symbol.keyFor(sym1) ); // id
// two symbols with the same description
const value1 = Symbol('hello');
const value2 = Symbol('hello');
var idk={test:true,[Symbol.toStringTag]:'e'}
consoel.log(idk)//e {test:true,[Symbol.toStringTag]:'e'}
idk.toString()//[object e]