JavaScript Number.isNaN() Method

24 Dec, 2021
Below is the example of the Number.isNaN() Method.
Example:<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(123);document.write(res);    }GFGFun();</script>
<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(123);document.write(res);    }GFGFun();</script>
Output:false
false
The Number.isNan method in JavaScript is used to determines 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 Used:1. Value :It is the value which 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.
Examples:
Input : 0/0
Output : true
     
Input : 213
Output : false

Input : '213'
Output : false

Input : 'hello'
Output : false

Input : NaN
Output : true


When an equation resulting in infinite value is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(0/0);document.write(res);    }GFGFun();</script>Output:Output : trueWhen a number is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(321);document.write(res);    }GFGFun();</script>Output:Output : falseWhen a number in string representation is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(213);document.write(res);    }GFGFun();</script>Output:Output : falseWhen a string is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN("hello");document.write(res);    }GFGFun();</script>Output:Output : falseWhen Nan is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(NaN);document.write(res);    }GFGFun();</script>Output:Output : true
When an equation resulting in infinite value is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(0/0);document.write(res);    }GFGFun();</script>Output:Output : true
<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(0/0);document.write(res);    }GFGFun();</script>
Output:
Output : true
When a number is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(321);document.write(res);    }GFGFun();</script>Output:Output : false
<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(321);document.write(res);    }GFGFun();</script>
Output:
Output : false
When a number in string representation is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(213);document.write(res);    }GFGFun();</script>Output:Output : false
<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(213);document.write(res);    }GFGFun();</script>
Output:
Output : false
When a string is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN("hello");document.write(res);    }GFGFun();</script>Output:Output : false
<script>function GFGFun() {  var res = "";  res = res + Number.isNaN("hello");document.write(res);    }GFGFun();</script>
Output:
Output : false
When Nan is passed as a parameter.<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(NaN);document.write(res);    }GFGFun();</script>Output:Output : true
<script>function GFGFun() {  var res = "";  res = res + Number.isNaN(NaN);document.write(res);    }GFGFun();</script>
Output:
Output : true
Supported Browsers:
Google Chrome 25 and above
Firefox 15 and above
Apple Safari 9 and above
Opera 15 and above
safari 9 and above
ysachin2314
javascript-math
JavaScript-Numbers
JavaScript
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.