JavaScript Type_conversion Guide
JavaScript type conversion happens implicitly (coercion) and explicitly. Understanding both is essential for avoiding bugs. The guide walks through Explicit Conversion, Implicit Coercion. String: `String(123)`, `(123).toString()`. Number: `Number("123")`, `+"123"`, `parseInt("123")`, `parseFloat("1.5")`. Boolean: `Boolean(1)`, `!!1`. JSON: `JSON.parse()`, `JSON.stringify()`. Explicit is safe and predictable — always prefer over implicit coercion. `"5" - 2` = 3 (string to number). `"5" + 2` = "52" (number to string — + is special). `!"hello"` = false (truthy/falsy). `if(value)` coerces to boolean. `==` coerces before comparing (use `===` instead). Falsy: 0, "", null, undefined, NaN, false. Be careful with loose equality: `"" == false` is true. The guide is organized into 2 sections that build on each other, each pairing a prose explanation with runnable code. Related guides: Arrays, Strings, Numbers, Math, Date. This is one of 145 JavaScript guides on JS Reference — see the full list on the guides page.