“JavaScript -Symbole” Code-Antworten

Symbole 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
QuietHumility

JavaScript -Symbole

let sym1 = Symbol()
let sym2 = Symbol('foo')
let sym3 = Symbol('foo')
Puzzled Peafowl

Symbole JavaScript


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

JavaScript -Symbol

// two symbols with the same description

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

console.log(value1 === value2); // false
SAMER SAEID

JavaScript -Symbol

// two symbols with the same description

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

Ähnliche Antworten wie “JavaScript -Symbole”

Fragen ähnlich wie “JavaScript -Symbole”

Weitere verwandte Antworten zu “JavaScript -Symbole” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen