Type Coercion & typeof

Understand why JavaScript silently converts types, how to check types with typeof, and how to convert values explicitly.

Step 1 of 5

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.

Think of it this way: Type coercion is like JavaScript being an overly helpful translator — it guesses what you meant, but sometimes it guesses wrong. Imagine telling a friend '5 plus 3' in a noisy room, and they hear 'five and three' and write '53' on paper. They tried to help, but misunderstood the operation.
Web Standard
Type coercion follows a precise set of rules defined in the ECMAScript specification. The `+` operator checks: if either operand is a string, convert the other to a string and concatenate. For `-`, `*`, `/`, and `%`, both operands are converted to numbers. These rules are consistent, even if the results seem surprising.
Learn more on MDN
JAVASCRIPTREAD ONLY
CONSOLE
Click "Run" to execute your code...