typeof, Truthy/Falsy, and == vs ===
Use typeof safely, recognize truthy/falsy, and compare values correctly with ===.
typeof, Truthy/Falsy, and == vs === is a free JavaScript Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Intro
Goal: Learn how typeof identifies types, which values are truthy or falsy, and when to use === instead of ==.
- typeof basics
- Truthy vs falsy
- Strict equality

typeof tour
typeof is fast for primitives. Note the legacy quirk: typeof null returns "object".
// typeof returns a string describing the type
console.log(typeof 42);
// "number"
console.log(typeof "hi");
// "string"
console.log(typeof true);
// "boolean"
console.log(typeof undefined);
// "undefined"
console.log(typeof 10n);
// "bigint"
console.log(typeof Symbol("x"));
// "symbol"
console.log(typeof null);
// "object" (historic quirk)

Truthy vs falsy (concept)
Falsy values: 0, -0, 0n, "", false, null, undefined, NaN. Everything else is truthy (e.g., "0", "false", [], {}, function(){}).

Testing truthiness
Use Boolean(x) or an if to see how a value behaves in conditions.
// Use Boolean(x) or if (x) to test truthiness
console.log(Boolean("0"));
// true (non-empty string)
console.log(Boolean(""));
// false (empty string)
console.log(Boolean([]));
// true (arrays are objects)
console.log(Boolean(0));
// false
console.log(Boolean({}));
// true

Loose equality pitfalls
== coerces types, creating confusing matches. Avoid it in most code.
// == performs type coercion: can be surprising
console.log(0 == false);
// true
console.log("" == 0);
// true
console.log(null == undefined);
// true
console.log("5" == 5);
// true (string coerced to number)

Strict equality
Use === and !== for predictable comparisons without type coercion.
// === compares without coercion: safer and clearer
console.log(0 === false);
// false
console.log("" === 0);
// false
console.log("5" === 5);
// false
console.log(5 === 5);
// true

Strict equality quiz
Quick check: Safe equality.

Recap
Recap: typeof identifies primitives (watch null), you learned common falsy values, and you saw why === beats == for clarity.

Frequently asked questions
Is the “typeof, Truthy/Falsy, and == vs ===” lesson free?
Yes — the full text of “typeof, Truthy/Falsy, and == vs ===” is free to read here on the web, and the JavaScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “typeof, Truthy/Falsy, and == vs ===”?
Use typeof safely, recognize truthy/falsy, and compare values correctly with ===. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start JavaScript Academy?
No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “typeof, Truthy/Falsy, and == vs ===” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this JavaScript Academy lesson?
Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Primitives vs Objects & Core Types
- typeof, Truthy/Falsy, and == vs ===
- Type Coercion: Safe Patterns to Avoid Surprises