<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JavaScript中变量提升</title>
<script type="text/javascript">
console.log(a); //结果为undefined
var a = 2;
/*
js会将变量的声明提升到顶部,可是赋值语句并不会提升。对于js来说,其实var a = 2是分为两步的:
1.var a;
2.a = 2;
而js只会将第一步提升到顶部,所以上面的语句等价于:
var a;
console.log(a);
a = 2;
*/
</script>
</head>
<body style="background-color: #CCE8CF;">
<h3 style="color: #cd1636;">JavaScript中变量提升</h3>
<a href="https://www.runoob.com/js/js-hoisting.html" target="_blank">
JavaScript变量提升参考网页https://www.runoob.com/js/js-hoisting.html
</a>
<br/>
<a href="https://blog.csdn.net/czh500/article/details/103455845" target="_blank">
javascript变量提升详解参考网页https://blog.csdn.net/czh500/article/details/103455845
</a>
<br/>
<a href="https://www.runoob.com/js/js-strict.html" target="_blank">
JavaScript严格模式(use strict)参考网页https://www.runoob.com/js/js-strict.html
</a>
</body>
</html>