
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Why is isNaN(null) == false in JS?
The isNan() method is used in JavaScript to check whether there’s the existence of an undefined value or can say checks for a NaN object.
Example
To check whether a JavaScript date is valid or not, you can try to run the following code −
<!DOCTYPE html> <html> <body> <script> var date1, date2; date1 = new Date("2018/1/1"); if( ! isNaN ( date1.getMonth() )) { document.write("Valid date1: "+date1); } else { document.write("<br>Invalid date1"); } date2 = new Date("20181/1"); if( ! isNaN ( date2.getMonth() )) { document.write("<br> Valid date2: "+date2); } else { document.write("<br>Invalid date2"); } </script> </body> </html>
The isNaN(null) == false is semantically correct. This is because null is not NaN.
- Related Articles
- isNAN() function in JavaScript
- Why do I need Babel JS?
- Double isNaN() method in Java
- Java Float isNaN() Method
- If ([] == false) is true, why does ([] || true) result in []? - JavaScript
- Why do we have External CSS and JS files
- Select MongoDB documents where a field either does not exist, is null, or is false?
- Check for illegal number with isNaN() in JavaScript
- Why in JavaScript, “if ('0' == false)” is equal to false whereas it gives true in “if(0)” statement?
- Why is address zero used for the null pointer in C/C++?
- Why TreeSet Does not allow null values in Java?
- Working with NULL and IS NOT NULL in MySQL
- SVG morphing in React JS
- PHP Why does this && not trigger as false?
- Why are NULL pointers defined differently in C and C++?

Advertisements