

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to check if a variable is NaN in JavaScript?
NaN is a JavaScript property, which is "Not-a-Number" value. To find out whether value is NaN, use the Number.isNaN() or isNan() method.
Example
Here’s an example to check if a variable in NaN in JavaScript
<!DOCTYPE html> <html> <body> <button onclick="display()">Check</button> <p id="test"></p> <script> function display() { var a = ""; a = a + isNaN(6234) + ": 6234<br>"; a = a + isNaN(-52.1) + ": -52.1<br>"; a = a + isNaN('Website') + ": '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>
- Related Questions & Answers
- JavaScript: How to check if a number is NaN or finite?
- How to check if a variable is boolean in JavaScript?
- How to check whether a NaN is a NaN or not in JavaScript?
- How to check if a variable is an integer in JavaScript?
- How to check if a variable is an array in JavaScript?
- How to check if a variable exists in JavaScript?
- How can I check if a JavaScript variable is function type?
- How to check if any value is NaN in a Pandas DataFrame?
- How do you check if a variable is an array in JavaScript?
- Python - Check if a variable is string
- How to check if a variable is NULL in C/C++?
- How do you check that a number is NaN in JavaScript?
- How do you test if a value is equal to NaN in Javascript?
- Check if variable is tuple in Python
- How to check if type of a variable is string in Python?
Advertisements