if (typeof myVar !== "undefined") {
console.log("myVar is DEFINED");
}
let id;
if(typeof id === 'undefined') {
console.log("id is undefined...");
}
if ( typeof query !== 'undefined' && query )
{
//do stuff if query is defined and not null
}
else
{
}
if (myVar != undefined){
console.log("Defined")
}
if (myVar != "undefined"){
console.log("Defined")
}
let myVar;
if (myVar === undefined){}
//!! Note: myVar == undefined would also check wether myVar is null
//alternatively
if (typeof myVar === 'undefined'){ }
if(typeof myVar !== "undefined")
let foo = undefined
//will return true
typeof foo === 'undefined'
if (angular.isDefined(var){
//myVariable is undefined
}
const obj =
{
"name": "John Doe",
"age": 39,
"Street": "Hauptstraße 5"
}
// street is undefined (its uppercase)
var { name: fullname, age, street } = obj;
// You need an array [...]
// if you will check one variable
TestUndef([age]);
// or more
TestUndef([fullname, street, age]);
console.log("All Ok");
function TestUndef(what) {
for (var that of what) {
if (typeof (that) == "undefined") {
throw new Error(`UNDEFINDED OBJECTS!`);
}
}
}
// no write "street" in line 5 lowercase, then its all ok.