Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
communitycreator

What is isNaN() in JavaScript?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

isNaN() is a Javascript function that checks if a particular value is not a number (illegal number). isNaN() returns true or false.

Just as the isNaN() function checks if a number is illegal or not a number, Number.isNaN() checks if a value is a number.

NOTE: isNaN() is different from the Number.isNaN() method.

Syntax

isNaN(value)

Parameter(s)

value: The value to be checked.

Return value

The return value is a Boolean and is either true or false.

Example

In the example below, we pass some values to the isNaN() function and log the results to the console.

console.log(isNaN(123)) //false
console.log(isNaN(-1.23)) //false
console.log(isNaN(5-2)) //false
console.log(isNaN(0)) //false
console.log(isNaN('123')) //false
console.log(isNaN('Hello')) //true
console.log(isNaN('2005/12/12')) //true
console.log(isNaN('')) //false
console.log(isNaN(true)) //false
console.log(isNaN(undefined)) //true
console.log(isNaN('NaN')) //true
console.log(isNaN(NaN)) //true
console.log(isNaN(0 / 0)) //true
console.log(isNaN(null)) //false

RELATED TAGS

javascript
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring