Fundamentals

Data types & type coercion

The primitive types and how JavaScript silently converts between them.

beginner Freshers

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