From 1ce2211c984eb8c7913d384b443a088dafadf7ba Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Mon, 15 Mar 2021 16:04:14 +0900 Subject: [PATCH 1/3] Recommend Number.isNaN(), not global isNan() Fixes https://github.com/mdn/content/issues/3026 --- .../index.html | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html b/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html index eea024dca7c6f1a..e2fa5b31c137456 100644 --- a/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html +++ b/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html @@ -119,9 +119,25 @@

Numbers

NaN + 5; // NaN
 
-

You can test for NaN using the built-in {{jsxref("Global_Objects/isNaN", "isNaN()")}} function:

+

You can reliably test for NaN using the built-in {{jsxref("Number.isNaN", "Number.isNaN()")}} function:

-
isNaN(NaN); // true
+
Number.isNaN(NaN); // true
+Number.isNaN('hello'); // false
+Number.isNaN('1'); // false
+Number.isNaN(undefined); // false
+Number.isNaN({}); // false
+Number.isNaN([1]) // false
+Number.isNaN([1,2]) // false
+
+ +

But don’t test for NaN using the global {{jsxref("Global_Objects/isNaN", "isNaN()")}} function, which has unintuitive behavior:

+ +
isNaN('hello'); // true
+isNaN('1'); // false
+isNaN(undefined); // true
+isNaN({}); // true
+isNaN([1]) // false
+isNaN([1,2]) // true
 

JavaScript also has the special values {{jsxref("Infinity")}} and -Infinity:

From 84e4d2193f01d993e7ce370eaf71cc712cab089f Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Tue, 16 Mar 2021 23:46:11 +0900 Subject: [PATCH 2/3] Add links to more-detailed explanations --- .../web/javascript/a_re-introduction_to_javascript/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html b/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html index e2fa5b31c137456..c99c242b3452246 100644 --- a/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html +++ b/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html @@ -119,7 +119,7 @@

Numbers

NaN + 5; // NaN
 
-

You can reliably test for NaN using the built-in {{jsxref("Number.isNaN", "Number.isNaN()")}} function:

+

You can reliably test for NaN using the built-in {{jsxref("Number.isNaN", "Number.isNaN()")}} function, which behaves just as its name implies:

Number.isNaN(NaN); // true
 Number.isNaN('hello'); // false
@@ -130,7 +130,7 @@ 

Numbers

Number.isNaN([1,2]) // false
-

But don’t test for NaN using the global {{jsxref("Global_Objects/isNaN", "isNaN()")}} function, which has unintuitive behavior:

+

But don’t test for NaN using the global {{jsxref("Global_Objects/isNaN", "isNaN()")}} function, which has unintuitive behavior:

isNaN('hello'); // true
 isNaN('1'); // false

From 1881ebfb5ba08328085bfe1b5c9d26feead45e63 Mon Sep 17 00:00:00 2001
From: "Michael[tm] Smith" 
Date: Tue, 16 Mar 2021 23:59:17 +0900
Subject: [PATCH 3/3] Apply suggestions from code review

Co-authored-by: Florian Scholz 
---
 .../web/javascript/a_re-introduction_to_javascript/index.html | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html b/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html
index c99c242b3452246..483590b43383fec 100644
--- a/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html
+++ b/files/en-us/web/javascript/a_re-introduction_to_javascript/index.html
@@ -119,7 +119,7 @@ 

Numbers

NaN + 5; // NaN
 
-

You can reliably test for NaN using the built-in {{jsxref("Number.isNaN", "Number.isNaN()")}} function, which behaves just as its name implies:

+

You can reliably test for NaN using the built-in {{jsxref("Number.isNaN", "Number.isNaN()")}} function, which behaves just as its name implies:

Number.isNaN(NaN); // true
 Number.isNaN('hello'); // false
@@ -130,7 +130,7 @@ 

Numbers

Number.isNaN([1,2]) // false
-

But don’t test for NaN using the global {{jsxref("Global_Objects/isNaN", "isNaN()")}} function, which has unintuitive behavior:

+

But don’t test for NaN using the global {{jsxref("Global_Objects/isNaN", "isNaN()")}} function, which has unintuitive behavior:

isNaN('hello'); // true
 isNaN('1'); // false