javascript check for undefined
snippet in javascript

js if not undefined

user3524

if (typeof myVar !== "undefined") {
    console.log("myVar is DEFINED");
}

javascript check for undefined

user2703

if (typeof myVariable === 'undefined'){
    //myVariable is undefined
}

javascript if undefined

user9924

if(typeof comment === 'undefined') {

  alert('Variable "comment" is undefined.');

} else if(comment === null){

  alert('Variable "comment" is null.');

}

test if is undefined javascript

user2357

let id;

if(typeof id === 'undefined') {
    console.log("id is undefined...");
}

js check if undefined

user8360

let foo = undefined
//will return true
typeof foo === 'undefined'

javacript detect undefined

user9177

//detecting undefined object property
if (typeof person.last_name === "undefined") {
    console.log("person last_name is undefined");
}

//detecting undefined variable 
if (typeof myVar === "undefined") {
    console.log("myVar is undefined");
}