Number.isNaN() In JavaScript
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
type
=
"text/javascript"
>
var num=0/0;
document.write("Output : " + num.isNaN());
</
script
>
chevron_rightfilter_noneOutput:
Output : true
- When a number is passed as a parameter.
<
script
type
=
"text/javascript"
>
var num=213;
document.write("Output : " + num.isNaN());
</
script
>
chevron_rightfilter_noneOutput:
Output : false
- When a number in string representation is passed as a parameter.
<
script
type
=
"text/javascript"
>
var test='213';
document.write("Output : " + test.isNaN());
</
script
>
chevron_rightfilter_noneOutput:
Output : false
- When a string is passed as a parameter.
<
script
type
=
"text/javascript"
>
var test='hello';
document.write("Output : " + test.isNaN());
</
script
>
chevron_rightfilter_noneOutput:
Output : false
- When Nan is passed as a parameter.
<
script
type
=
"text/javascript"
>
var check=Nan;
document.write("Output : " + check.isNaN());
</
script
>
chevron_rightfilter_noneOutput:
Output : true
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.