Update isNumber.md

This commit is contained in:
Angelos Chalaris
2019-03-19 09:41:49 +02:00
committed by GitHub
parent 0daced5fd5
commit a5b0abeb36

View File

@ -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;