using typeof on undefined javascript code example
Example 1: javascript typeof undfined
var x;
if (typeof x === 'undefined') {
// these statements execute
}
Example 2: js this returns undefined
function foo() {
console.log(this);
}
// normal function call
foo(); // `this` will refer to `window`
// as object method
var obj = {bar: foo};
obj.bar(); // `this` will refer to `obj`
// as constructor function
new foo(); // `this` will refer to an object that inherits from `foo.prototype`