languages/why-does-5-3-give-53-in-javascript-type-coercion-step-by-step.md

Why does "5" + 3 give "53" in JavaScript? Type coercion, step by step

Programming languages · 4 min read ·

Why does `"5" + 3` give `"53"` while `"5" - 3` gives `2`? It is not random. JavaScript follows a short recipe called type coercion: it decides what kind of value each side is, converts where it must, and then calculates.

Pick two values and an operator in the explorer, watch the steps, and learn to predict every strange result before you run it.

Two boxes, the string "5" and the number 3, joined by a plus sign into the string "53"

$ ls languages/

see all →