Fundamentals
Data types & type coercion
The primitive types and how JavaScript silently converts between them.
JavaScript has seven primitives — string, number, boolean, null, undefined, symbol, bigint — plus the object type for everything else.
Coercion is like a translator who guesses your intent — helpful until the guess is wrong, which is why `===` (no translator) is safer.
Key concepts
1
Coercion is the automatic conversion between types. == coerces before comparing (0 == "0" is true), while === compares without coercion and should be your default.
Coercion==0 == "0"true===
2
Truthy / falsy — the falsy values are false, 0, "", null, undefined, NaN and 0n. Everything else is truthy, including "0" and empty arrays/objects.
Truthy / falsyfalse0""null
javascript
typeof 42; // 'number'
typeof 'hi'; // 'string'
typeof null; // 'object' (a historical bug)
typeof undefined; // 'undefined'
0 == '0'; // true (coerced)
0 === '0'; // false (no coercion)
Boolean(''); // false
Boolean('0'); // true