mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-11 07:00:41 -04:00
fix(curriculum): expand on null in javascript comparisons and conditionals review (#63671)
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user