parseInt
You can convert a string to an integer using the built-inparseInt()
function. This takes the base for the conversion as an optional second argument, which you should always provide:
Number.isNan
You can reliably test forNaN
using the built-inNumber.isNaN()
function, which behaves just as its name implies:
isFinite
JavaScript also has the special valuesInfinity
and-Infinity
:
Copy to Clipboard
You can test for Infinity
, -Infinity
and NaN
values using the built-in isFinite()
function: