<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>函数、变量预解析</title>
</head>
<body>
<script type="text/javascript">
//函数声明时:能显示123,因为把function提到了show()前了,预解析了
show();
function show(){
console.log(123)
}
//函数赋值时:不能显示123;这就是与上述的区别
show();
var show=function(){
console.log(123)
}
//变量也可以预解析
console.log(a);
var a=123;
//函数与变量哪个会更先预解析呢??答案是函数先解析。
function a(){};
var a;
console.log(a); //a()
</script>
</body>
</html>
函数与变量的预解析
最新推荐文章于 2022-08-09 17:17:33 发布