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

  1. Number: Integers and floats. Includes Infinity and NaN (Not-a-Number, e.g., result of "hello" / 2).
  2. BigInt: For gigantically large numbers.
  3. String: Text. Always in quotes. JS has no " char " type, only strings.
  4. Boolean: Logical type. Only true or false.
  5. Null: A special value that WE ASSIGN ourselves. Means " intentionally empty " .
  6. 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.