Home >Web Front-end >JS Tutorial >Summary of basic JavaScript knowledge (6) Functions and initial scope (Part 2)
This time I will bring you a basic JavaScript knowledge summary. There are a total of eleven knowledge points. Basic JavaScript knowledge summary (6)Function, initial scope (below) ) The following is a practical case, let’s take a look.
Initial exploration of scope
Scope definition: Variables (variables act on, also known as context) and the area where functions take effect (can be accessed)
Global and local variables
Scope access order
You can access things outside the function inside the function. Variables defined on the script tag are called global variables, and variables defined inside the function are called local variables
//a是全局变量var a = 123;function test(){ console.log(a);//打印出来是123 //b是局部变量 var b = 123; function demo(){ var c = 234; console.log(a); console.log(b); } console.log(c);//报错c is not defined;}; test();console.log(b);//报错b is not defined function test(){ var a = 123; }function demo(){ var b = 12; }//不能相互访问
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!
Related reading:
Summary of basic JavaScript knowledge (6) Functions, initial scope (Part 1)
Summary of basic JavaScript knowledge (4) Conditional statements, loop statements
The above is the detailed content of Summary of basic JavaScript knowledge (6) Functions and initial scope (Part 2). For more information, please follow other related articles on the PHP Chinese website!