Q:

javascript is variable undefined

//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

 var x;

if (typeof x === "undefined") {
  txt = "x is undefined";
} else {

    txt = "x is defined";
} 
0

New to Communities?

Join the community