0
Q:

javascript if undefined

if(myVar === null) {
	console.log("Element is undefined");
}
8
if (typeof myVariable === 'undefined'){
    //myVariable is undefined
}
9
if(typeof comment === 'undefined') {

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

} else if(comment === null){

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

}
5
//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");
}
2
let foo = undefined
//will return true
typeof foo === 'undefined'
1

New to Communities?

Join the community