What is Symbol ?
A Symbol is something like a character, which is used as a conventional representation of someother object.
What is a symbol in programming language ?
A Symbol is a primitive data type which is in human-readable form.
Symbol can be used as identifiers.
Symbol is a function that is used to identify the object properties.
What are the features of Symbol ?
Some of the features of Symbol is,
1. Symbol() method will always returns a unique value.
2. Symbol values may be used as an identifier for object properties.
3. Symbols are immutable, just like numbers and strings.
4. Symbols cannot be typecasted to primitive data types.
Symbol – This defines the Symbol
description – Its a String value passed as param, this is an optional parameter,
1. Converting Symbol with variable
Symbol ‘id’ is combined with var ‘user’.
Printing the user name value = Abdul Kalaam
Printing the combined user[id] value = Some User ID Value
|1||Symbol.hasInstance()||Symbol.hasInstance() property is used to determine if a constructor object recognizes an object as its instance.|
|2||Symbol.isConcatSpreadable()||Symbol.isConcatSpreadable() property is used to configure if an object should be flattened to its array elements.|
|3||Symbol.match()||Symbol.match() property is a method to identify the matching of a regular expression against a string.|
|4||Symbol.prototype()||Symbol.prototype() property is used for produce the prototype for the symbol constructor.|
|5||Symbol.replace()||Symbol.replace() property replaces matched substring of a string.|
|6||Symbol.search()||Symbol.search() property returns the index within a string that matches with the regular expression.|
|7||Symbol.split()||Symbol.split() property splits a string at the indices that match the regular expression.|
|8||Symbol.toPrimitive()||Symbol.toPrimitive() property is used to convert an object to its equivalent primitive value.|
|9||Symbol.unscopables()||Symbol.unscopables() property is a well-known object property whose property name are excluded from with environment.|
|Sno||Methods / Function||Description|
|1||Symbol.for()||Symbol.for() method is used to search for existing symbol in a runtime-wide symbol registry with the provided key and returns if it is found.|
Otherwise new symbol gets created with this key.
|2||Symbol.keyFor()||Symbol.keyFor() method uses the global symbol registry to look up the key for the symbol.|
So it doesn’t work for non-global symbols.
If the symbol is not global, it won’t be able to find it and returns undefined.
|3||Symbol.toString()||Symbol.toString() method is used to return a string representation of an object.|