我正在学习 javascript,我偶然发现了这种行为,它不会在代码末尾执行函数 f2()。
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();
如果undefined没有放在 " " 中,那么最后的 f2() 将被跳过(被忽略?)。如果放入“”,则执行 f2()。有人可以向我解释这种行为的可能原因吗?先感谢您!
jeck猫
相关分类