null and undefined check in javascript

This tutorial will cover difference between null & undefined and how to check null & undefined in JavaScript.

Diffrence between null & undefined

null is a special value that means “no value”.You can assign “null” to any variables

undefind means, the variable not declared or value not assigned to variables.(Undefind will through error message)

check null & undefined in JavaScript

Below code will explain how to check variable is null or undefined in JavaScript

function isNull(data) {
     var isNotValid = false;
     try {
         if (typeof data === "undefined") {
             isNotValid = true;
         } else if (data === null) {
             isNotValid = true;
     } catch (e) {
         isNotValid = true;
     return isNotValid;
Latest posts by W3TWEAKS (see all)


Leave a Reply

Your email address will not be published. Required fields are marked *