Symbol Coercion Throws
What you'll learn: Why symbols aggressively prevent implicit conversion to strings or numbers, throwing errors to protect you from bugs.
The Anti-Coercion Type
Remember how JavaScript usually tries to be helpful by coercing values automatically? Symbols take the opposite approach. They're the only primitive type that outright refuses implicit coercion to strings or numbers. Instead of silently converting (and potentially creating bugs), they throw a TypeError.
This is by design. Symbols are meant to be unique identifiers, and converting them would violate their uniqueness guarantee. JavaScript forces you to be explicit.
What Throws and What Doesn't
const sym = Symbol('mySymbol');
// These THROW TypeError:
"prefix" + sym; // ❌ TypeError: Cannot convert a Symbol value
sym - 0; // ❌ TypeError: Cannot convert a Symbol value
Number(sym); // ❌ TypeError: Cannot convert a Symbol value
// Boolean coercion is ALLOWED:
Boolean(sym); // ✅ true (all symbols are truthy)
if (sym) { } // ✅ Works fine
// Explicit string conversion is ALLOWED:
String(sym); // ✅ "Symbol(mySymbol)"
sym.toString(); // ✅ "Symbol(mySymbol)"
Notice the pattern: implicit conversions throw, but explicit conversions (when you deliberately call String() or toString()) work fine.
Why This Protection Exists
If symbols coerced silently, you might accidentally use them in string operations expecting a meaningful label, but actually breaking uniqueness. The error forces you to think: "Do I really want to convert this symbol, and if so, why?"
Key Takeaway: Symbols throw TypeError on implicit string/number coercion to prevent accidental misuse, but allow explicit conversion and always coerce to true in boolean contexts.