Skip to main content

Posts

Featured

isNaN() vs Number.isNaN()

  NaN (an acronym for not a number) is a JavaScript datatype used to describe entries that are not numbers. isNaN() and Number.isNaN() are both JavaScript methods used to check if an entry is not a number. isNaN() It converts a parameter into the number data type and then checks if it is a number or not. It returns a boolean value that indicates whether a value is the reserved value NaN. That is to say, it returns 'true' if the value if the parameter is not a number and 'false' if it is. Number.isNaN() It also returns a boolean value that indicates whether a value is the reserved value NaN. But like the isNaN() method, it doesn't force the parameter into the number data type. Hence only parameters that are both of the number data type and are NaN result in true. Comparison Examples: Example 1:  The isNaN() method returns true for the parameter because after forcing into a number data type it is still not a number. While we get false from the Number.isNaN() because a...

Latest Posts