全局变量的声明
var a =20;
var b,c=3;
console.log(b,c,a)
b = 10;
document.write(b);
运行结果:undefined,3,20;
局部变量的声明
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
var a = 20;
if (a <= 20) {
var b = "hello";
}
console.log(b);
if (a <= 20) {
let c = "hello";
}
console.log(c);
</script>
</body>
</html>
运行结果: