fix(curriculum): expand on null in javascript comparisons and conditionals review (#63671)

This commit is contained in:
l3onhard
2025-11-21 09:27:57 +01:00
committed by GitHub
parent edbdc415e2
commit 8a9035a774
2 changed files with 34 additions and 8 deletions

View File

@@ -12,15 +12,28 @@ dashedName: review-javascript-comparisons-and-conditionals
- **Comparisons and `undefined`**: A variable is `undefined` when it has been declared but hasn't been assigned a value. It's the default value of uninitialized variables and function parameters that weren't provided an argument. `undefined` converts to `NaN` in numeric contexts, which makes all numeric comparisons with `undefined` return `false`.
```js
console.log(undefined > 0); // false
console.log(undefined < 0); // false
console.log(undefined == 0); // false
console.log(undefined < 0); // false (NaN < 0 is false)
console.log(undefined >= 0); // false (NaN >= 0 is false)
```
- **Comparisons and `null`**: The `null` type represents the intentional absence of a value. When using the equality operator, `null` and `undefined` are considered equal. However, when using the strict equality operator (`===`), which checks both value and type without performing type coercion, `null` and `undefined` are not equal:
- **Comparisons and `null`**: The `null` type represents the intentional absence of a value. `null` converts to `0` in numeric contexts, which may result in unexpected behaviour in numeric comparisions:
```js
console.log(null < 0); // false (0 < 0 is false)
console.log(null >= 0); // true (0 >= 0 is true)
```
- When using the equality operator (`==`), `null` and `undefined` only equal each other and themselves:
```js
console.log(null == undefined); // true
console.log(null == 0); // false
console.log(undefined == NaN); // false
```
- However, when using the strict equality operator (`===`), which checks both value and type without performing type coercion, `null` and `undefined` are not equal:
```js
console.log(null === undefined); // false
```

View File

@@ -600,15 +600,28 @@ console.log(Number.isNaN(undefined)); // false
- **Comparisons and `undefined`**: A variable is `undefined` when it has been declared but hasn't been assigned a value. It's the default value of uninitialized variables and function parameters that weren't provided an argument. `undefined` converts to `NaN` in numeric contexts, which makes all numeric comparisons with `undefined` return `false`.
```js
console.log(undefined > 0); // false
console.log(undefined < 0); // false
console.log(undefined == 0); // false
console.log(undefined < 0); // false (NaN < 0 is false)
console.log(undefined >= 0); // false (NaN >= 0 is false)
```
- **Comparisons and `null`**: The `null` type represents the intentional absence of a value. When using the equality operator, `null` and `undefined` are considered equal. However, when using the strict equality operator (`===`), which checks both value and type without performing type coercion, `null` and `undefined` are not equal:
- **Comparisons and `null`**: The `null` type represents the intentional absence of a value. `null` converts to `0` in numeric contexts, which may result in unexpected behaviour in numeric comparisions:
```js
console.log(null < 0); // false (0 < 0 is false)
console.log(null >= 0); // true (0 >= 0 is true)
```
- When using the equality operator (`==`), `null` and `undefined` only equal each other and themselves:
```js
console.log(null == undefined); // true
console.log(null == 0); // false
console.log(undefined == NaN); // false
```
- However, when using the strict equality operator (`===`), which checks both value and type without performing type coercion, `null` and `undefined` are not equal:
```js
console.log(null === undefined); // false
```