Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Number.isNaN() Method

JavaScript Number.isNaN() Method

The Javascript Number.isNan method in JavaScript is used to determine whether the passed value is NaN(Not a Number) and is of the type “Number”. In JavaScript, the value NaN is considered a type of number. 

Syntax:

Number.isNaN(value)

Parameters: 

  • Value: It is the value that is to be tested for NaN. 

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. 

Below is an example of the Number.isNaN() Method.

Example 1: This example checks if 123 is a number or not.

Javascript




function GFGFun() {
    let res = "";
    res = res + Number.isNaN(123);
    console.log(res);
}
GFGFun();


Output:

false

Example 2: When an equation resulting in an infinite value is passed as a parameter. 

Javascript




function GFGFun() {
    let res = "";
    res = res + Number.isNaN(0 / 0);
    console.log(res);
}
GFGFun();


Output:

Output : true

Example 3: When a number is passed as a parameter. 

Javascript




function GFGFun() {
    let res = "";
    res = res + Number.isNaN(321);
    console.log(res);
}
GFGFun();


Output:

Output : false

Example 4: When a number in string representation is passed as a parameter. 

Javascript




function GFGFun() {
    let res = "";
    res = res + Number.isNaN(213);
    console.log(res);
}
GFGFun();


Output:

Output : false

Example 5: When a string is passed as a parameter. 

Javascript




function GFGFun() {
    let res = "";
    res = res + Number.isNaN("hello");
    console.log(res);
}
GFGFun();


Output:

Output : false

Example 5: When Nan is passed as a parameter. 

Javascript




function GFGFun() {
    let res = "";
    res = res + Number.isNaN(NaN);
    console.log(res);
}
GFGFun();


Output:

Output : true

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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments