You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/type-coercion.mdx
+10-4Lines changed: 10 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -347,7 +347,7 @@ value || defaultValue // logical OR
347
347
348
348
### The 8 Falsy Values (Memorize These!)
349
349
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`.
351
351
352
352
```javascript
353
353
// THE FALSY EIGHT
@@ -361,6 +361,10 @@ Boolean(undefined) // false
361
361
Boolean(NaN) // false
362
362
```
363
363
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
+
364
368
### Everything Else Is Truthy!
365
369
366
370
This includes some surprises:
@@ -834,7 +838,7 @@ if (x == true) { } // Don't do this!
834
838
if (x) { } // Do this instead
835
839
836
840
// 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!)
838
842
if (x ===0) { } // Clear intent
839
843
840
844
// BAD: Truthy check when you need specific type
@@ -860,7 +864,7 @@ function process(count) {
860
864
861
865
2.**Implicit vs Explicit** — Know when JS converts automatically vs when you control it
0 commit comments