“Símbolo de JavaScript” Código de respuesta

símbolos 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

Métodos de símbolos 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
SAMER SAEID

símbolos de JavaScript

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

JS Symbole ()

let sym = Symbol('foo')
typeof sym      // "symbol"
let symObj = Object(sym)
typeof symObj   // "object"
Enchanting Echidna

Símbolo de JavaScript

// two symbols with the same description

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

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

Símbolo de JavaScript

// two symbols with the same description

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

Respuestas similares a “Símbolo de JavaScript”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código