Chapter 4 of 16All chapters
Chapter 4 of 16
Data types
Primitives, objects and typeof.
The primitives
There are seven: string, number, boolean, null, undefined, symbol and bigint. Everything else, arrays and functions included, is an object.
- typeof reports the type, with one famous exception: typeof null returns "object".
- That is a bug from the first version of the language, kept because too much code depends on it.
undefined and null
undefined means a value was never set. null means someone set it to nothing on purpose. Keeping that distinction makes intent readable later.