<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>变量的作用域</title>
</head>
<body>
<!-- 全局变量:直接在script直接使用var定义的变量
局部变量:在函数中定义的变量
-->
<script>
var s1=10;
function fn2(){
// 如果函数中定义变量,都是局部变量
var s2=20;
console.log(s2);
window.s3+=10;
console.log(s3);
}
fn2();
console.log(s1);
</script>
</body>
</html>
operation result