Skip to content

Commit 34e7ee4

Browse files
authored
Update null-undefined.md
1 parent 846e11a commit 34e7ee4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

docs/javascript/null-undefined.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ JavaScript (and by extension TypeScript) has two bottom types : `null` and `unde
1010

1111
### Checking for either
1212

13-
Fact is you will need to deal with both. Just check for either with `==` check.
13+
Fact is you will need to deal with both. Interestingly in JavaScript with `==`, `null` and `undefined` are only equal to each other:
1414

1515
```ts
16-
/// Imagine you are doing `foo.bar == undefined` where bar can be one of:
17-
console.log(undefined == undefined); // true
16+
// Both null and undefined are only `==` to themselves and each other:
17+
console.log(null == null); // true (of course)
18+
console.log(undefined == undefined); // true (of course)
1819
console.log(null == undefined); // true
1920

21+
2022
// You don't have to worry about falsy values making through this check
2123
console.log(0 == undefined); // false
2224
console.log('' == undefined); // false
@@ -32,7 +34,9 @@ function foo(arg: string | null | undefined) {
3234
}
3335
```
3436

35-
One exception, root level undefined values which we discuss next.
37+
> You could also do `== undefined`, but `== null` is more conventional/shorter.
38+
39+
One exception, root level `undefined` values which we discuss next.
3640

3741
### Checking for root level undefined
3842

0 commit comments

Comments
 (0)