JavaScript NaN Function

JavaScript's number feature enables you to represent numeric and floating numbers. JavaScript number has a particular value called NaN function, which means for Not-a-Number.

NaN is an attribute of the global javascript object. The global object is used to show the window object in web browsers. There are used to NaN function in different ways.

  • The javascript shows NaN value in windows in browsers.
    window.NaN
  • The javascript shows the NaN value as a global object in Node.js.
    global.NaN
  • The NaN has the typeof number as shown in the following code:
    console.log(typeof NaN);
    We can assign a variable to NaN in two ways. It's a non-number value. It checks if a number is legitimate.
  • var value = NaN

Syntax

JavaScript provides us with the global function isNaN(). It returns true if its argument is NaN of the operation.

The NaN function shows the true or false output of the given syntax.

Examples

The following example shows multiple types of the number or NaN values using javascript.

Example 1:

The given an example shows NaN number in javascript using different display values. Here, we use positive, negative, and simple equation data.

Output

You can see the Boolean format data to check input value is NaN.

JavaScript NaN Function

Example 2: The given example shows NaN number in javascript using different display values. Here, we use number, string, equation, and date format input value.

Output

You can see the Boolean format data to check input value is NaN.

JavaScript NaN Function

Example 3:

The given an example shows NaN numbers in javascript using different display values here. It uses positive, negative, and simple equation data. We can use a different method to check given number is Nan or not.

Output

You can see the Boolean format data to check input value is NaN.

JavaScript NaN Function

Example 4:

The given an example shows NaN number in javascript using different display values. Here, we use other functions such as parseInt and parseFloat.

Output

You can see the Boolean format data to check input value is NaN.

JavaScript NaN Function

Example 5:

The given example shows the NaN number in the javascript equation and other functions using different display values.

Output

You can see the Boolean format data to check input value is NaN.

JavaScript NaN Function

Why use the NaN Function

JavaScript NaN function shows the result of a failed operation on numbers, including:

  • It is used for Parsing numbers.
  • Javascript is used to undefine as an operand for operation.
  • Javascript is used NaN function as an operand
  • Javascript is used to indeterminate forms
  • Javascript is used for Passing invalid arguments for math functions.

Supported Browser

The following browser is used and supports the javascript NaN function. Almost all browsers and the latest version are supported by the NaN function.

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 4 and above
  • Opera 3 and above
  • safari 1 and above

Conclusion

The NaN() function is used to get or check given number is NaN or not using javascript. It is a global function to work with all types of data.