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.
// 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
asyncIterator Returns the default AsyncIterator for an object
hasInstance Determines if a constructor object recognizes an object as its instance
isConcatSpreadable Indicates if an object should be flattened to its array elements
iterator Returns the default iterator for an object
match Matches against a string
matchAll Returns an iterator that yields matches of the regular expression against a string
replace Replaces matched substrings of a string
search Returns the index within a string that matches the regular expression
split Splits a string at the indices that match a regular expression
species Creates derived objects
toPrimitive Converts an object to a primitive value
toStringTag Gives the default description of an object
description Returns a string containing the description of the symbol