js函数中变量声明提前

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">

/**
* 在js中 变量声明提前
*
* @type {string}
*/

var name="zhangsan";
function test(){
console.log(name);
var name="lisi";
console.log(name);
}
//等价于下面的
function tt(){
var name;
console.log(name)
name = "lisi";
console.log(name);
}
test();
</script>
</head>
<body>

</body>
</html>
原文地址:https://www.cnblogs.com/hwgok/p/5715558.html