What Do We Store in Boxes?
In JavaScript, a variable is not tied to a type forever. You can put a number in it, and later — a string. This is called dynamic typing.
1. Seven Primitive Types
- Number: Integers and floats. Includes
InfinityandNaN(Not-a-Number, e.g., result of"hello" / 2). - BigInt: For gigantically large numbers.
- String: Text. Always in quotes. JS has no " char " type, only strings.
- Boolean: Logical type. Only
trueorfalse. - Null: A special value that WE ASSIGN ourselves. Means " intentionally empty " .
- Undefined: A value assigned by JS itself if a variable is created but has nothing in it.
2. New and Special
- BigInt: For huge numbers that don't fit into Number.
- Symbol: Unique identifiers.
3. Object (Complex Type)
Everything else in JS is an Object. It can store entire collections of data.
Tip
To find out the type, use typeof:
typeof 42; // "number"
typeof "Hello"; // "string"
Warning
typeof null returns " object " . This is an official bug in the language that cannot be fixed due to backward compatibility. Just memorize it.