重学ES系列之变量的作用范围
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>变量的作用范围</title>
</head>
<body>
</body>
<script>
// var与let
/*
var v1 = '1';
console.log(v1); // 1
v2 = '2';
console.log(v2);
console.log(v3);
var v3 = 'v3';
var v4 = 'v4';
var v4 = 'v41';
console.log(v4);
for (var index = 0; index < 5; index++) {
console.log(index);
}
console.log(index);
*/
// ***
/*
let a1 = 'a1';
console.log(a1);
a2= 'a2';
console.log(a2);
console.log(a3);
let a3 = 'a3';
let a4 = 'a4';
let a4 = 'a41';
console.log(a4);
for (let index = 0; index < 5; index++) {
console.log(index);
}
console.log(index);
*/
/*
function fun(p) {
var p = '1';
console.log(p);
}
fun('0');
*/
/*
function fun1 (m) {
let m = '1';
console.log('m');
}
fun1('0');
*/
/*
function fun2(p) {
{
let f = '1';
console.log(f);
}
}
fun2('0');
*/
/*
1. let 不允许重复声明
2. let 创建局部变量(块级)
3. 同一个块中,不允许重复的变量声明
*/
</script>
</html>
作者:Vam的金豆之路
主要领域:前端开发
我的微信:maomin9761
微信公众号:前端历劫之路