Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Absence of Value & Conversion · Lesson 15 of 15

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

🤖
Values change type more often than you'd think — sometimes on purpose, sometimes not. 🔄

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));    // false
String(), Number(), and Boolean() explicitly convert a value to the given type.

A 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));    // 1
Number() follows consistent, if occasionally surprising, rules for each type.
🤖
Implicit coercion is where a lot of 'weird JavaScript' jokes come from — but the rules are actually consistent. 😅

Implicit 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)
+ prefers concatenation when a string is involved, but - always coerces both sides to numbers.
Fill in the blank

Because - always converts both sides to numbers, the expression "5" - 1 evaluates to ____.

Quick check

What does "5" + 1 evaluate to?

True or false

Number('hello') evaluates to NaN because 'hello' cannot be converted into a meaningful number.

Chapter quiz

Absence of Value & Conversion

10 questions · pass with 60% — just like in the app.

Quick check

What does null represent?

True or false

typeof null returns the string 'object', a well-known JavaScript quirk.

Fill in the blank

A variable that is declared but never given a value automatically holds ____.

Quick check

What is the key difference between null and undefined?

True or false

Accessing a property that doesn't exist on an object returns undefined rather than throwing an error.

Quick check

Which function explicitly converts a value to a string?

Fill in the blank

Number('hello') evaluates to ____ because the text cannot be converted into a meaningful number.

Quick check

What does "5" + 1 evaluate to?

Fill in the blank

Because - always converts both sides to numbers, "5" - 1 evaluates to ____.

True or false

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 →