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;
}
Leave a Reply