JavaScript Number.isNaN() Method
Last Updated :
11 Mar, 2024
The Number.isNaN()
method in JavaScript is used to determine whether the passed value is NaN (Not-a-Number) and its type is Number.
Number.isNaN() Syntax
Number.isNaN(value)
Number.isNaN() Parameters
- Value: It is the value that is to be tested for NaN.
Number.isNaN() Return Value:
The Number.isNaN() method in JavaScript returns true if the passed value is Nan and is of the type number, else it returns false.
JavaScript Number.isNaN() Method Examples
Example 1: Checking if a Number is NaN in JavaScript
The GFGFun()
function initializes an empty string res
. It then appends the result of the Number.isNaN(123)
method call to res
. Since 123
is a valid number, Number.isNaN()
returns false
.
Javascript
function GFGFun() {
let res = "" ;
res = res + Number.isNaN(123);
console.log(res);
}
GFGFun();
|
Example 2: Checking if Division by Zero Results in NaN
The GFGFun()
function initializes an empty string res
. It then appends the result of the expression Number.isNaN(0 / 0)
to res
. Since division by zero results in NaN, Number.isNaN()
returns true
.
Javascript
function GFGFun() {
let res = "" ;
res = res + Number.isNaN(0 / 0);
console.log(res);
}
GFGFun();
|
Example 3: Checking if a Number is NaN in JavaScript
The function GFGFun()
initializes an empty string res
, then appends the result of Number.isNaN(321)
to res
. Since 321
is a valid number, Number.isNaN()
returns false
.
Javascript
function GFGFun() {
let res = "" ;
res = res + Number.isNaN(321);
console.log(res);
}
GFGFun();
|
We have a complete list of Javascript Number Object methods, to check those please go through this Javascript Number Complete reference article.
Supported Browsers:
- Google Chrome 25 and above
- Firefox 15 and above
- Apple Safari 9 and above
- Opera 15 and above
- safari 9 and above
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...