I am learning about JavaScript symbols and from what I have read they are used to protect object property key overwrites. In the following code I create two symbols of the same variable name and use them as object keys. I want to know how to access the data assigned to either one of the "symbol" keys at the bottom of the program. If I'm misunderstanding the purpose of symbols altogether please point it out.
var id = Symbol("my id"); // Create a Symbol
var user = {
name:"Bob",
age:30,
[id]:"my id 12345" // Use it as a property key and add some data
}
var id = Symbol("my different id"); // Create a new Symbol
user[id] = "my different id 9876" // Assign it with some new data
console.log(user);
/* The object contains both symbols. No overwrites!
{
name: "Bob",
age: 30,
Symbol(my id): "my id 12345",
Symbol(my different id): "my different id 9876"
}
*/