console.log(n);//undefined
fn();//fn is not defined
if(false){ //无论条件是否成立,都执行预解释
var n=1; //n 是预解释
function fn(){ //为啥fn没有预解释???
console.log(1);
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这个叫做“变量提升”
一般是不建议在
if else里面定义函数的,老版本的ie是会预解析的,新版本浏览器不会。你好歹把w3c或者阮一峰的js教程看一看再提问