
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a Number is NaN in JavaScript
NaN is a JavaScript property, which is Not-a-Number value. This shows it is not a legal number. Here’s the syntax −
Syntax
Number.NaN
To find out whether a number is NaN, use the Number.isNaN() or isNan() method. Here’s an example to check −
Example
<!DOCTYPE html> <html> <body> <button onclick="display()">Check</button> <p id="test"></p> <script> function display() { var a = ""; a = a + isNaN(434) + ": 434<br>"; a = a + isNaN(-23.1) + ": -23.1<br>"; a = a + isNaN('Hello') + ": 'Hello'<br>"; a = a + isNaN(NaN) + ": NaN<br>"; a = a + isNaN('') + ": ''<br>"; a = a + isNaN(0) + ": 0<br>"; a = a + isNaN(false) + ": false<br>"; document.getElementById("test").innerHTML = a; } </script> </body> </html>
Advertisements