Hand-picked HTML and CSS code examples, tutorials and articles
CSS Gallery, jQuery plugins

null and undefined check in javascript screenshot

null and undefined check in javascript

This tutorial will cover diffrence between null & undefind 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;
}

Advertisement