Hello Friends 👋,
Welcome To Infinitbility! ❤️
Javascript provides multiple ways to check value is a number or not isNaN(), and typeof methods are some of those.
Now, we are going to see how we can use the isNaN(), and typeof methods to check the given value is number.
Let’s start today’s tutorial How to check value is number or not in javascript?
Javascript isNaN() method
Javascript provides the isNaN() method to identify data is number or not just like is full form Not a number.
it will return true id provided value is not a number, else return false.
Let check isNaN() method.
const value = 10
// number
isNaN(value) //false
// object
isNaN({}) //true
// float
isNaN(1.2) //false
// string
isNaN('infinitbility') //true
isNaN() method return false, if a value is a number.
output
Javascript typeof method
Javascript provides typeof operator to check the type of data, when we pass any number, float then typeof return number.
const value = 2
typeof value //'number'