I am learning javascript and I tumbled upon this behaviour where it would not execute the function f2() at the end of the code.
function f1() {
var oneT = 55;
console.log(oneT);
}
f1();
console.log(typeof(oneT));
function f2() {
if (typeof(oneT) == undefined) {
console.log("oneT can't be read outside the f1() as it's scope is limited to the fn f1().");
}
}
f2();
If the undefined is not put in " ", then the f2() at the end is skipped (overlooked?). If put in " ", then it executes the f2(). Can someone explain to me the possible reason for this behaviour? Thank you in advance!
"undefined" != undefinedifis not fulfilled no matter whether you test== undefinedor== " "(if that's what you mean), because thetypeofsomething is always a string