πŸ”΄ HardType CoercionπŸ’» Output Question

Symbol coercion rules

πŸ’‘

Hint

Symbols throw TypeError on implicit string coercion β€” a deliberate design to prevent accidental use as object keys when you meant to use strings.

What does this output?

const sym = Symbol('test');

console.log(typeof sym);
console.log(sym.toString());
console.log(sym.description);
console.log(sym + '');
console.log(Boolean(sym));

Correct Output

symbol
Symbol(test)
test
TypeError: Cannot convert a Symbol value to a string
true

Why this output?

Explanation: typeof returns "symbol". .toString() explicitly converts: "Symbol(test)". .description gives just the label: "test". Implicit string coercion (+ "") throws TypeError β€” Symbols resist coercion. Boolean conversion: all Symbols are truthy.

Key Insight: Symbols throw TypeError on implicit string coercion β€” a deliberate design to prevent accidental use as object keys when you meant to use strings.

More Type Coercion Output Questions

🟒 EasyLoose equality coercionβ†’πŸŸ‘ MediumAddition vs concatenationβ†’πŸŸ‘ MediumFalsy values comparisonβ†’πŸŸ‘ MediumNaN comparisonβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz