Symbols Are Not Enumerable
You'll learn why symbol-keyed properties are invisible to JavaScript's standard object inspection methods.
Why Symbol Properties Stay Hidden
When you use a symbol as an object key, that property becomes hidden from enumeration. This means it won't show up in for...in loops, Object.keys(), or Object.values(). It also won't be included when you use JSON.stringify() to serialize an object.
Think of symbol properties like secret compartments in a desk. When someone opens the drawers (Object.keys()), they see all the regular items, but the hidden compartments remain invisible unless you know exactly where to look.
How This Affects Your Code
const id = Symbol('id');
const user = {
name: 'Alice',
age: 30,
[id]: 12345
};
// Standard enumeration misses the symbol
for (let key in user) {
console.log(key); // 'name', 'age' (no id!)
}
console.log(Object.keys(user)); // ['name', 'age']
console.log(Object.values(user)); // ['Alice', 30]
// JSON serialization ignores symbols completely
console.log(JSON.stringify(user)); // '{"name":"Alice","age":30}'
Even though the id property exists and you can access it directly with user[id], it stays invisible to these common inspection methods. You must use Object.getOwnPropertySymbols() (from your previous lesson) to retrieve symbol properties.
This non-enumerable behavior is by design—it lets you add metadata or internal properties to objects without interfering with existing code that iterates over keys.
Key Takeaway: Symbol properties are intentionally hidden from for...in, Object.keys(), and JSON.stringify(), making them perfect for private or meta-level data that shouldn't appear in standard object iteration.