JavaScript isNull | How to Check for null

The value null represents the object value or variable value is don’t have any value(“No value”). There is no isNull function in JavaScript script to find without value objects.

However you can build your own isNull() function with some logics.

Examples of Check null in JavaScript

Let’s see the example of it:-

Code JavaScript check if null

You can use the qualities of the abstract equality operator to do this:

Strict equality operator:-

Because null == undefined is true, the above code will catch both null and undefined.

Just by using if

JavaScript isNull function

You can create function isNull like:-


JavaScript isNull function

Q: How to JavaScript check not null?

Answer: Try to check with ‘null’ as below code: 3 ways to check for “not null”. My recommendation is to use the Strict Not Version.

Strict Not Version

Non-strict Not Version

Double Not Version

Q: What is the Type of null in JavaScrip?

Answer: Type of null is an object in JS, you can check the type of any variable with typeof keyword. for example

Do comment if you have any questions or suggestion on this topic.

Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.