From 097b28758a222911bc8570e8515013b78773e534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P?= Date: Sat, 25 Nov 2023 15:38:50 +0100 Subject: [PATCH 1/2] Comparing `undefined` to `undefined` --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 95f8b00c..df61e058 100644 --- a/README.md +++ b/README.md @@ -1790,6 +1790,24 @@ true; - [**7.2.15** Abstract Equality Comparison](https://262.ecma-international.org/11.0/index.html#sec-abstract-equality-comparison) - [An in-depth explanation](https://blog.campvanilla.com/javascript-the-curious-case-of-null-0-7b131644e274) + +## Comparing `undefined` to `undefined` + +`undefined` if equal to `undefined` but is not greater than or equal to `undefined`: + +``` +null == null; // true +null >= null; // true +undefined == undefined; // true +undefined >= undefined; // false +``` + +### 💡 Explanation: + +- If at least one of the two values is not a string, JavaScript attempts to convert the non-numeric types into numeric values. +- [`Number(undefined)` returns `NaN`](#undefined-and-number). +- [`NaN` is not a `NaN`](#nan-is-not-a-nan). + ## Same variable redeclaration JS allows to redeclare variables: From 2cbd93990fdc15bea7d065b5c3de4af467839483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P?= Date: Sat, 25 Nov 2023 15:42:20 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index df61e058..3724a9d3 100644 --- a/README.md +++ b/README.md @@ -1790,12 +1790,11 @@ true; - [**7.2.15** Abstract Equality Comparison](https://262.ecma-international.org/11.0/index.html#sec-abstract-equality-comparison) - [An in-depth explanation](https://blog.campvanilla.com/javascript-the-curious-case-of-null-0-7b131644e274) - ## Comparing `undefined` to `undefined` -`undefined` if equal to `undefined` but is not greater than or equal to `undefined`: +`undefined` is equal to `undefined` but is not greater than or equal to `undefined`: -``` +```js null == null; // true null >= null; // true undefined == undefined; // true