Last updated on Mar 28, 2022 by Suraj Sharma
In this tutorial, you’ll learn two ways to check if a given value is a number in JavaScript
The isNaN()
function determines whether the passed argument is NaN
(not a number) or not.
It returns false
if the passed argument is a number
else returns true
.
isNaN(45) // false
isNaN('Hello') // true
isNaN(NaN) // true
isNaN(45.02) // false
isNaN('45') // false
The typeof
operator returns a string representing the type of a value/operand.
typeof 45 === 'number' // true
typeof 'hello' === 'number' // false
typeof 56.78 === 'number' // true
Related Solutions
Rate this post
Suraj Sharma is the founder of Future Gen AI Services. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.