代码语言:javascript复制
<!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');
更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/119862192