JavaScript scope

JavaScript Scope

A collection of scope accessible variables.

JavaScript scope

In JavaScript, objects and functions are also variables.

In JavaScript, scope is a collection of accessible variables, objects, and functions.

JavaScript function scope: The scope is modified within the function.

JavaScript local scope

Variables are declared within the function, and the variables are local scope.

Local variables: can only be accessed inside the function.

  局部变量在声明的函数内可以访问。myFunction();
document.getElementById("demo").innerHTML =
"我的名字叫 " +  typeof Name;
function myFunction() 
{
    var Name = "jack";
}
Continuing Learning
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p>访</p>
<p id="demo"></p>
<script>
myFunction();
document.getElementById("demo").innerHTML =
" " + typeof Name;
function myFunction()
{
var Name = "jack";
}
</script>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
图片放大关闭