0Pricing
JavaScript Academy · Lesson

typeof, Truthy/Falsy, and == vs ===

Use typeof safely, recognize truthy/falsy, and compare values correctly with ===.

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, Truthy/Falsy, and == vs === — illustration 1

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)
typeof, Truthy/Falsy, and == vs === — illustration 2

All lessons in this course

  1. Primitives vs Objects & Core Types
  2. typeof, Truthy/Falsy, and == vs ===
  3. Type Coercion: Safe Patterns to Avoid Surprises
← Back to JavaScript Academy