Null Undefined check in Javascript

This is on of the most disastrous flaws in complex web applications, where there are hundreds of people working on different modules and writing their own respective javascript methods. For them to properly handle the null/undefined scenarios, it’s always better to create a separate method something like isNullOrUndefined in one of the javascript util/validation files as:

This would help maintaining the consistency throughout the application whenever a null/undefined scenario is to be checked. You just need to pass the variable as a parameter to this method. In turn, the method returns a flag that could be a true/false value.

Note that ‘===’ checks for both the type and value, and is a stricter way to check, whereas ‘==’ does the type conversion of the operands and checks only for the values. I have a grand example to demonstrate this:

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.