if (typeof myVar !== "undefined") {
console.log("myVar is DEFINED");
}
if(typeof comment === 'undefined') {
alert('Variable "comment" is undefined.');
} else if(comment === null){
alert('Variable "comment" is null.');
}
let id;
if(typeof id === 'undefined') {
console.log("id is undefined...");
}
if (t === undefined) {
return 'Undefined value!';
}
let myVar;
if (myVar === undefined){}
//!! Note: myVar == undefined would also check wether myVar is null
//alternatively
if (typeof myVar === 'undefined'){ }
if (typeof myVariable === 'undefined'){
//myVariable is undefined
}
if (typeof something != "undefined") {
// ...
}
let foo = undefined
//will return true
typeof foo === 'undefined'
if(myVar === null) {
console.log("Element is 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.