Course contentsShow
← JavaScript
Lesson 55 of 2,7232. Values and TypesFree lesson

How === Works: Type and Value

Learn that strict equality checks both type and value without performing any type coercion.

How === Works: Type and Value

What you'll learn: How strict equality (===) compares values by checking both their type and their actual value.

The Core Idea

When you use === (strict equality), JavaScript performs two checks in sequence:

  1. Are the types the same? If not, return false immediately.
  2. Are the values the same? If yes, return true.

This is different from == (loose equality), which attempts to convert types before comparing. With ===, no conversion ever happens—JavaScript looks at exactly what you give it.

How It Works in Practice

// Same type AND same value → true
5 === 5                    // true
"hello" === "hello"        // true
true === true              // true

// Different types → false (no conversion attempted)
5 === "5"                  // false (number vs string)
0 === false                // false (number vs boolean)
null === undefined         // false (different types)

// Same type, different values → false
5 === 7                    // false
"hello" === "Hello"        // false (case matters)

Think of It Like Security Clearance

Imagine === as a strict security checkpoint. To pass through (return true), you need both the right badge type AND the right ID number. If your badge type is wrong, you're rejected immediately—no questions asked. If your badge type is correct but your ID doesn't match, still rejected.

Why This Matters

Strict equality prevents subtle bugs caused by JavaScript's type coercion. You always know exactly what you're comparing.

Key Takeaway: === checks both type and value without any conversion—both must match exactly for the result to be true.