Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

what is symbol in javascript

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.
Comment

Symbol Methods javascript

// 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
Comment

javascript Symbol Methods

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.
Comment

JavaScript Symbol

// two symbols with the same description

const value1 = Symbol('hello');
const value2 = Symbol('hello');

console.log(value1 === value2); // false
Comment

Symbol Methods javascript

// 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
Comment

JavaScript Symbol

// two symbols with the same description

const value1 = Symbol('hello');
const value2 = Symbol('hello');
Comment

what does the symbol function do in javascript

var idk={test:true,[Symbol.toStringTag]:'e'}
consoel.log(idk)//e {test:true,[Symbol.toStringTag]:'e'}
idk.toString()//[object e]
Comment

PREVIOUS NEXT
Code Example
Javascript :: Turn A 2D Array Into A JSON 
Javascript :: Recursion In A Class Function 
Javascript :: If you wish to set a method equal to another method in the class 
Javascript :: square brackets javascript object key 
Javascript :: Moving Zeros To The End 
Javascript :: nestjs prisma controller 
Javascript :: Iterate Through the Keys of an Object with a for...in Statement 
Javascript :: How to sum to small numbers 
Javascript :: livewire multiple root elements detected. this is not supported 
Javascript :: Exporting Objects with the Exports Object in electron 
Javascript :: How to Loop Through an Array with a While Loop in JavaScript 
Javascript :: geteliment by id in javascript 
Javascript :: how to set javascript load order in html 
Javascript :: sap rpa desktop studio activate excel macro 
Javascript :: simple JSX example 
Javascript :: Solution-1--solution options for reverse bits algorithm js 
Javascript :: event 
Javascript :: javascript get max value in array of objects 
Javascript :: redirect in react-router-dom v6 
Javascript :: electron js execute command line 
Javascript :: how to take input from user in javascript console 
Javascript :: dart to json 
Javascript :: custom hook react 
Javascript :: how to add suffix to a string in javascript 
Javascript :: javascript DOM SELECT 
Javascript :: Finding palindrome using for loop 
Javascript :: reading an array from python to js 
Javascript :: post css nesting nuxt 
Javascript :: simple counter with react hook 
Javascript :: TypeError: _enzymeAdapterReact.EnzymeAdapter is not a constructor 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =