JavaScript theorytheory 0/50 · 0%
Fundamentals · easy

3. Types and coercion

The seven primitives and the equality traps.

Primitives are string, number, boolean, null, undefined, bigint and symbol; everything else is an object. `typeof null` famously returns `"object"`.

`==` coerces types before comparing; `===` does not. Always use `===`.

"1" == 1;   // true  — coerced
"1" === 1;  // false — different types
typeof 10n; // "bigint"

Token amounts exceed 2^53, so use `bigint` (or a library's BigNumber) rather than `number` for wei values.

Check your understanding

  1. 1. Why use `bigint` for wei amounts?

  2. 2. What does `typeof null` return?

  3. 3. Which comparison avoids coercion?