Type Coercion & typeof
Understand why JavaScript silently converts types, how to check types with typeof, and how to convert values explicitly.
Why "5" + 3 equals "53"
When you use an operator on two values of different types, JavaScript doesn't just give up — it tries to help by converting one value to match the other. This automatic conversion is called type coercion.
The most infamous example: `"5" + 3` gives you `"53"`, not `8`. Why? The `+` operator works for both addition (numbers) and concatenation (strings). When one side is a string, JavaScript assumes you meant concatenation and converts the number to a string. So `"5" + 3` becomes `"5" + "3"`, which is `"53"`.
But with other operators like `-`, `*`, and `/`, strings get converted to numbers: `"5" - 3` gives `2`, because subtraction only makes sense with numbers. This inconsistency is one of the most common sources of bugs in JavaScript.