From 0cdd291043838a1676c1cb621efd15c00cb83709 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 3 Aug 2023 18:17:25 +0300 Subject: [PATCH] expanded on the null/undefined/NaN checking... Signed-off-by: Alex A. Naanou --- js-types-n-oop.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/js-types-n-oop.js b/js-types-n-oop.js index fb3ccf7..69cc0d8 100755 --- a/js-types-n-oop.js +++ b/js-types-n-oop.js @@ -209,8 +209,27 @@ // a couple notable types that can be counter-intuitive: - typeof(null) // -> 'object' typeof(NaN) // -> 'number' + typeof(null) // -> 'object' + +// For NaN use: + + isNaN(NaN) // -> true + +// And for null/undefined a more generic and non-strict comparison is +// recommended: + + var x = null + var y = undefined + + x == null // -> true + y == null // -> true + +// Strict comparisons also work but unless explicitly required they +// should be avoided in favor of the non-strict comparison shown above: + + x === null // -> true + y === undefined // -> true