From 9d2699e4ec5c5945bbbcc2cf58be09a63bd4c0a1 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 19 Mar 2019 09:41:49 +0200 Subject: [PATCH] Update isNumber.md --- snippets/isNumber.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snippets/isNumber.md b/snippets/isNumber.md index a692c8f9a..ff0bfe9b9 100644 --- a/snippets/isNumber.md +++ b/snippets/isNumber.md @@ -2,7 +2,8 @@ Checks if the given argument is a number. -Use `typeof` to check if a value is classified as a number primitive. Because `typeof NaN` is equal to `number`, the `val === val` is for protection. NaN compares unequal (via ==, !=, ===, and !==) to any other value, including to another NaN value. +Use `typeof` to check if a value is classified as a number primitive. +To safeguard against `NaN`, check if `val === val` (as `NaN` has a `typeof` equal to `number` and is the only value not equal to itself). ```js const isNumber = val => typeof val === 'number' && val === val;