Skip to content

Commit 8f7047e

Browse files
committed
fix: improve technical accuracy in type coercion concept page
1 parent 9ed8042 commit 8f7047e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

docs/concepts/type-coercion.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ value || defaultValue // logical OR
347347

348348
### The 8 Falsy Values (Memorize These!)
349349

350-
There are exactly **8 values** that convert to `false`. Everything else is `true`.
350+
There are **8 common values** that convert to `false`. Everything else is `true`.
351351

352352
```javascript
353353
// THE FALSY EIGHT
@@ -361,6 +361,10 @@ Boolean(undefined) // false
361361
Boolean(NaN) // false
362362
```
363363

364+
<Info>
365+
**Technical note:** There's actually a 9th falsy value: [`document.all`](https://developer.mozilla.org/en-US/docs/Web/API/Document/all). It's a legacy browser API that returns `false` in boolean context despite being an object. You'll rarely encounter it in modern code, but it exists for backwards compatibility with ancient websites.
366+
</Info>
367+
364368
### Everything Else Is Truthy!
365369

366370
This includes some surprises:
@@ -834,7 +838,7 @@ if (x == true) { } // Don't do this!
834838
if (x) { } // Do this instead
835839

836840
// BAD: Using == with 0 or ""
837-
if (x == 0) { } // Might match "", null behavior is weird
841+
if (x == 0) { } // Matches "", but not null (null == 0 is false!)
838842
if (x === 0) { } // Clear intent
839843

840844
// BAD: Truthy check when you need specific type
@@ -860,7 +864,7 @@ function process(count) {
860864

861865
2. **Implicit vs Explicit** — Know when JS converts automatically vs when you control it
862866

863-
3. **The 8 falsy values**`false`, `0`, `-0`, `0n`, `""`, `null`, `undefined`, `NaN` — everything else is truthy
867+
3. **The 8 common falsy values**`false`, `0`, `-0`, `0n`, `""`, `null`, `undefined`, `NaN` — everything else is truthy (plus the rare `document.all`)
864868

865869
4. **+ is special** — It prefers string concatenation if ANY operand is a string
866870

@@ -888,7 +892,7 @@ function process(count) {
888892
The `+` operator, when one operand is a string, performs string concatenation. The number `3` is converted to `"3"`, resulting in `"5" + "3" = "53"`.
889893
</Accordion>
890894

891-
<Accordion title="Question 2: What are the 8 falsy values in JavaScript?">
895+
<Accordion title="Question 2: What are the 8 common falsy values in JavaScript?">
892896
**Answer:**
893897
1. `false`
894898
2. `0`
@@ -900,6 +904,8 @@ function process(count) {
900904
8. `NaN`
901905

902906
Everything else is truthy, including `[]`, `{}`, `"0"`, and `"false"`.
907+
908+
**Bonus:** There's also a 9th falsy value — `document.all` — a legacy browser API you'll rarely encounter.
903909
</Accordion>
904910

905911
<Accordion title="Question 3: Why does [] == ![] return true?">

0 commit comments

Comments
 (0)