Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Primitive Data Types · Lesson 12 of 15

Booleans

A free lesson from Swipe Coding · JavaScript, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Just two values, endless uses — booleans are deceptively powerful. ✅

A boolean has only two possible values: true and false. Booleans are perfect for representing yes/no or on/off states, and they are commonly the result of a comparison.

const isLoggedIn = true;
const hasPermission = false;
console.log(isLoggedIn, hasPermission);
Two boolean variables, one true and one false.

Comparison operators like ===, !==, >, <, >=, and <= evaluate to a boolean, making them the most common way booleans show up in real code.

console.log(5 > 3);    // true
console.log(5 === 10); // false
Each comparison produces a boolean result.
🤖
Only six falsy values exist in all of JavaScript — worth memorizing them. 📋

JavaScript also treats every value as either "truthy" or "falsy" whenever a boolean is expected, such as inside an if condition. There are exactly six falsy values: false, 0, "" (empty string), null, undefined, and NaN. Every other value — including "0" as a string, or an empty array [] — is truthy.

if ("") {
  console.log("This won't run");
}
if ("hello") {
  console.log("This will run"); // a non-empty string is truthy
}
The empty string is falsy, so the first block is skipped; the non-empty string is truthy, so the second runs.
Fill in the blank

A value that behaves like false in a boolean context, such as 0 or an empty string, is called ____.

Quick check

Which of these values is falsy in JavaScript?

True or false

An empty string '' is falsy, but a string containing any character, like 'no', is truthy.

Chapter quiz

Primitive Data Types

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

True or false

JavaScript has a separate char type for single characters, just like Java.

Quick check

Which of these correctly creates a string in JavaScript?

Fill in the blank

Backtick strings are called ____ literals and let you embed expressions inside ${ }.

Quick check

What does `Hello, ${name}!` produce when name is 'Ada'?

True or false

JavaScript has just one number type that covers both whole numbers and decimals.

Fill in the blank

Dividing zero by zero, or doing math with non-numeric data, produces the special value ____.

Quick check

What does 10 % 3 evaluate to?

Quick check

Which of these values is falsy in JavaScript?

True or false

An empty string '' is falsy, while a non-empty string like 'no' is truthy.

Quick check

What does the + operator do when used between two strings?

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 →