How do you explicitly convert between types?
Quick answer
Use Number(), String(), Boolean() (or parseInt/parseFloat for parsing). Be explicit at data boundaries.
In detail
Prefer explicit conversion when reading user input or API data: `Number(x)`, `String(x)`, `Boolean(x)`. `parseInt`/`parseFloat` parse leading numbers from strings ('12px' → 12). The unary `+` is a terse number cast, and `!!x` is a terse boolean cast.
1Number("42"); // 42
2parseInt("12px"); // 12
3String(42); // "42"
4Boolean(0); // false
5+"3.5"; // 3.5
6!!"hi"; // trueWhy interviewers ask this: Checks habits around safe, explicit type handling.
This is 1 of 118+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299