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. This is lesson 2 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, and your progress syncs across the web and the CoddyKit app. The JavaScript Academy course includes 3 lessons in total.
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.

Learn JavaScript with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 59
- Lessons
- 200
Frequently Asked Questions
Is the “typeof, Truthy/Falsy, and == vs ===” lesson free?
Yes — any 3 lessons of the JavaScript Academy learning path, including “typeof, Truthy/Falsy, and == vs ===”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The JavaScript Academy course includes 3 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 3.
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