Roadmap › JavaScript (ES5 → ES2025) & TypeScript Basics › Module: Language Basics
Lessons in this course (16)
1. Data types, typeof and equality
Basic★ Must knowLesson 1 of 16
Primitive types (immutable, compared by value): string, number, bigint, boolean, undefined, symbol, null. Everything else is an object (objects, arrays, functions, dates, maps), compared by reference.
js
typeof "hi" // "string"
typeof 42 // "number"
typeof 10n // "bigint"
typeof undefined // "undefined"
typeof null // "object" ← historical bug
typeof [] // "object" → use Array.isArray([])
typeof function(){} // "function"
0.1 + 0.2 === 0.3 // false (floating point) → compare with Number.EPSILON or use integers (paise)
NaN === NaN // false → Number.isNaN(x)
// == converts types (coercion); === compares type and value
"5" == 5 // true
"5" === 5 // false
null == undefined // true
null === undefined // false
[] == false // true (weird coercion) → always use ===Falsy values: false, 0, -0, 0n, "", null, undefined, NaN. Everything else is truthy (including "0", [], {}).