MediumModern JS💻 Output Question

Symbol keys hidden from Object.keys

💡

Hint

Symbol keys are non-enumerable by default — hidden from Object.keys, for...in, and JSON.stringify.

What does this output?

const id = Symbol('id');
const user = { name: 'Alice', [id]: 42 };
console.log(user.name);
console.log(user[id]);
console.log(Object.keys(user).length);

Correct Output

Alice
42
1

Why this output?

Explanation: Symbol keys must be accessed directly with [id]. Object.keys only returns string keys — length is 1.

Key Insight: Symbol keys are non-enumerable by default — hidden from Object.keys, for...in, and JSON.stringify.

More Modern JS Output Questions

EasyDestructuring defaults apply only for undefinedEasyObject spread — later properties winMediumOptional chaining prevents TypeError on missing propertiesMediumNullish coalescing ?? vs OR ||

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz