Type Conversion
A free lesson from Swipe Coding · JavaScript, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Type conversion means changing a value from one type to another. JavaScript lets you do this explicitly using built-in functions, or it can happen implicitly (automatically) behind the scenes — sometimes with surprising results.
console.log(String(42)); // "42"
console.log(Number("42")); // 42
console.log(Boolean(0)); // falseA few Number() conversion rules worth knowing: converting an empty string gives 0, converting a non-numeric string like "hello" gives NaN, and converting true or false gives 1 or 0.
console.log(Number("")); // 0
console.log(Number("hello")); // NaN
console.log(Number(true)); // 1Implicit coercion is a common source of confusion. The + operator concatenates as text whenever either side is a string — but other math operators, like -, always try to convert both sides to numbers first.
console.log("5" + 1); // "51" (string concatenation)
console.log("5" - 1); // 4 (numeric subtraction)Because - always converts both sides to numbers, the expression "5" - 1 evaluates to ____.
What does "5" + 1 evaluate to?
Number('hello') evaluates to NaN because 'hello' cannot be converted into a meaningful number.
Absence of Value & Conversion
10 questions · pass with 60% — just like in the app.
What does null represent?
typeof null returns the string 'object', a well-known JavaScript quirk.
A variable that is declared but never given a value automatically holds ____.
What is the key difference between null and undefined?
Accessing a property that doesn't exist on an object returns undefined rather than throwing an error.
Which function explicitly converts a value to a string?
Number('hello') evaluates to ____ because the text cannot be converted into a meaningful number.
What does "5" + 1 evaluate to?
Because - always converts both sides to numbers, "5" - 1 evaluates to ____.
typeof null correctly returns the string 'null'.
Keep your streak going in Swipe Coding
Swipe through every level of JavaScript on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →