Skip to content
Guest
Learn JavaScript · Course Syllabus Show lessons
Language Foundations · 8 min read · Beginner

Data Types, Strict Equality & Nullish Coalescing

Understand JavaScript's primitive types, why === beats ==, how truthy/falsy values work, and how ?? sets safe defaults.

What you'll learn

  • Recognize primitive types: string, number, boolean, null, undefined, bigint, symbol
  • Always prefer strict equality (===) over loose equality (==)
  • Use nullish coalescing (??) to handle default values safely without breaking 0 or empty strings

JavaScript values fall into primitives (string, number, boolean, null, undefined, symbol, bigint) and objects (plain objects, arrays, functions, dates).

Always Use Strict Equality (===)

Loose equality (==) silently coerces types ("5" == 5 is true, "" == 0 is true), causing subtle bugs. Strict equality (===) checks both type and value.

✓ Strict Equality & Nullish Defaults
const score = 0;
const display = score ?? 100; // 0!
if (score === 0) { ... }
✕ Surprising Type Coercion
const score = 0;
const display = score || 100; // 100 (bug!)
if ("0" == 0) { ... } // true!

Use ?? when 0, false, or '' are valid values and you only want a fallback for null or undefined.

Fill-in-the-Blank Exercise

Strict Comparison & Safe Default

Check strict equality and fall back to 'Guest' only when username is null or undefined.

const isAdmin = role  'admin';
const label = username  'Guest';

Try It Yourself

Explore === vs == and ?? vs ||
Live Result
Console Output

No console output yet. Try calling console.log(...) in JS.

Check Your Understanding

Score: 0 / 1

1. What does `0 ?? 42` evaluate to in JavaScript?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind