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
}
function divisors(integer) {
let i, flag = true;
let arr=[];
for(i = 2; i <= integer - 1; i++) {
if (integer % i == 0) {
flag = false;
arr.push(i)
}
}
if (flag == true)
console.log(integer + " is prime");
else
console.log(arr)
}
console.log(divisors(15))
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.