Gothdo - 10 months ago 27

Javascript Question

There are multiple ways to check if a number is finite.

- Using function:
`Number.isFinite()`

`Number.isFinite(number)`

- Comparing to :
`Infinity`

`Math.abs(number) !== Infinity`

I'm usinghere in case the number is`Math.abs()`

.`-Infinity`

- Comparing to :
`Number.POSITIVE_INFINITY`

`Math.abs(number) !== Number.POSITIVE_INFINITY`

Are there any differences between using these three methods? I'm assuming that

`Infinity`

Answer

2 and 3 are the same because `Number.POSITIVE_INFINITY === Infinity`

. 1 and 2 will handle `NaN`

differently, see http://www.ecma-international.org/ecma-262/6.0/#sec-number.isfinite