JavaScript Number.NaN

The syntax to access the NaN property is:

Number.NaN

NaN is accessed using the Number class name.


Example: Using Number.NaN

// verify value is a number
function verify(x) {
  if (isNaN(x)) {
    return Number.NaN;
  }
  return x; // only return if number is not NaN
}

console.log(verify(5)); // 5
console.log(verify(5.45)); // 5.45
console.log(verify(Infinity)); // Infinity

console.log(verify("five")); // NaN
console.log(verify(undefined)); // NaN
console.log(verify([1, 2, 3, 4])); // NaN

Output

5
5.45
Infinity
NaN
NaN
NaN

Recommended Reading:

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges