Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

symbols javascript

Symbols are primatives for unique values in javascript

> Symbol(value) returns a unique symbol

> Symbol.for(value) returns a unique symbol, but two calls using the 
same key will return the same symbol, within the scope

They can be useful because they are hidden from most iteration functions.
For ex, if you want to add a value to an object that you got back from a
third-party api. This will make sure your value doesn't appear in iteration
functions, and also won't require changing how the api is set up
Comment

javascript symbols

let sym1 = Symbol()
let sym2 = Symbol('foo')
let sym3 = Symbol('foo')
Comment

JavaScript Symbol

// two symbols with the same description

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

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

JavaScript Symbol

// two symbols with the same description

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

Symbols Javascript


let sym2 = Symbol('foo')
let sym3 = Symbol('foo')
 
		 console.log(Symbol(sym2==sym3)); /*false, symbols are guaranteed to be unique*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: read string using stream nodejs 
Javascript :: linear search javascript 
Javascript :: queryselector change alternative 
Javascript :: get element attribute jquery 
Javascript :: javascript identifiers 
Javascript :: map react 
Javascript :: document.getelementsbyname 
Javascript :: mongoose max record 
Javascript :: js date option 
Javascript :: what does connect do in redux 
Javascript :: react router dom v6 navigate replace 
Javascript :: find if json property is of type date type 
Javascript :: react native login screen 
Javascript :: how to use settimeout in react 
Javascript :: switch expression bools 
Javascript :: Difference between “ == “ and “ === “ operators. 
Javascript :: Authentication handling in javascript 
Javascript :: escape character javascript 
Javascript :: javascript function hoisting 
Javascript :: Use the parseInt Function 
Javascript :: jquery accordion toggle close open 
Javascript :: fetch thingy 
Javascript :: type time angular 
Javascript :: like operator mangodb 
Javascript :: onchange vue 
Javascript :: mdn trimstart 
Javascript :: angular file upload 
Javascript :: read more css js 
Javascript :: factory function vs constructor javascript 
Javascript :: Computed Property 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =