Can symbols in js be really reassigned? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can symbols in js be really reassigned?

In the code, let id = Symbol(); let user = { [id] : 12, }; user[id] = 14; alert(user[id]); Here, the value of symbol id is 14 on alert ie. Reassigned. But in specifications, they say symbols cannot be reassigned, so whats the concept here???

8th Jan 2022, 7:30 AM
Himansh
Himansh - avatar
1 Answer
+ 4
Every symbol returned by Symbol() is unique, so every symbol has its own identity. https://www.freecodecamp.org/news/how-did-i-miss-javascript-symbols-c1f1c0e1874a/
8th Jan 2022, 4:17 PM
👑 ShadowCipher 🇦🇲
👑 ShadowCipher 🇦🇲 - avatar