Q:

null undefined javascript

var myVar=null;

if(myVar === null){
    //I am null;
}

if (typeof myVar === 'undefined'){
    //myVar is undefined
}
2
if( typeof myVar === 'undefined' || myVar === null ){
    // myVar is undefined or null
}
0
Undefined  used for unintentionally missing values.

Null       used for intentionally missing values. 
3
// 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).
}
1

New to Communities?

Join the community