← Cheat Sheets
JavaScript Truthy, Falsy and Types
Equality and type pitfalls.
# JavaScript Truthy, Falsy and Types
Equality and type pitfalls.
**Falsy values:** `false`, `0`, `-0`, `0n`, `""`, `null`, `undefined`, `NaN`. Everything else is truthy (including `"0"`, `[]` and `{}`).
| Expression | Result |
|---|---|
| `typeof "a"` | `"string"` |
| `typeof 1` | `"number"` |
| `typeof null` | `"object"` (historic quirk) |
| `typeof undefined` | `"undefined"` |
| `typeof []` | `"object"` (use `Array.isArray`) |
| `typeof (() => {})` | `"function"` |
| `1 == "1"` | `true` (type coercion) |
| `1 === "1"` | `false` |
| `NaN === NaN` | `false` (use `Number.isNaN`) |
Prefer `===` and `!==`.