From 8a9035a774466cbcb45b7b60bc96f8b18bfe4269 Mon Sep 17 00:00:00 2001 From: l3onhard Date: Fri, 21 Nov 2025 09:27:57 +0100 Subject: [PATCH] fix(curriculum): expand on null in javascript comparisons and conditionals review (#63671) --- .../6723c554025f449f4f39c3f5.md | 21 +++++++++++++++---- .../6723d3cfdd0717d3f1bf27e3.md | 21 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/curriculum/challenges/english/blocks/review-javascript-comparisons-and-conditionals/6723c554025f449f4f39c3f5.md b/curriculum/challenges/english/blocks/review-javascript-comparisons-and-conditionals/6723c554025f449f4f39c3f5.md index 85b33ae61bc..c752b89b6d2 100644 --- a/curriculum/challenges/english/blocks/review-javascript-comparisons-and-conditionals/6723c554025f449f4f39c3f5.md +++ b/curriculum/challenges/english/blocks/review-javascript-comparisons-and-conditionals/6723c554025f449f4f39c3f5.md @@ -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 ``` diff --git a/curriculum/challenges/english/blocks/review-javascript/6723d3cfdd0717d3f1bf27e3.md b/curriculum/challenges/english/blocks/review-javascript/6723d3cfdd0717d3f1bf27e3.md index e4e0531dad1..79140ad78b7 100644 --- a/curriculum/challenges/english/blocks/review-javascript/6723d3cfdd0717d3f1bf27e3.md +++ b/curriculum/challenges/english/blocks/review-javascript/6723d3cfdd0717d3f1bf27e3.md @@ -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 ```