if (typeof myVar !== "undefined") { console.log("myVar is DEFINED"); }
var myVar=null; if(myVar === null){ //I am null; } if (typeof myVar === 'undefined'){ //myVar is undefined }
if( typeof myVar === 'undefined' || myVar === null ){ // myVar is undefined or null }
Undefined used for unintentionally missing values. Null used for intentionally missing values.
// simple check do the job if (myString) { // comes here either myString is not null, // or myString is not undefined, // or myString is not '' (empty). }
if (typeof value !== 'undefined' && value) { //deal with value' };
//check if string is undefined if (typeof myVar === 'undefined'){ console.log("I am not defined"); } //check if string is empty, null, or 0 var emptyString=""; if (emptyString) { console.log("im not empty"); }
// simple check do the job if (myVar) { // comes here either myVar is not null, // or myVar is not undefined, // or myVar is not '' (empty string). }