Booleans
A free lesson from Swipe Coding · JavaScript, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
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);
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
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
}A value that behaves like false in a boolean context, such as 0 or an empty string, is called ____.
Which of these values is falsy in JavaScript?
An empty string '' is falsy, but a string containing any character, like 'no', is truthy.
Primitive Data Types
10 questions · pass with 60% — just like in the app.
JavaScript has a separate char type for single characters, just like Java.
Which of these correctly creates a string in JavaScript?
Backtick strings are called ____ literals and let you embed expressions inside ${ }.
What does `Hello, ${name}!` produce when name is 'Ada'?
JavaScript has just one number type that covers both whole numbers and decimals.
Dividing zero by zero, or doing math with non-numeric data, produces the special value ____.
What does 10 % 3 evaluate to?
Which of these values is falsy in JavaScript?
An empty string '' is falsy, while a non-empty string like 'no' is truthy.
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 →