Home > Web Front-end > JS Tutorial > Summary of basic JavaScript knowledge (6) Functions and initial scope (Part 2)

Summary of basic JavaScript knowledge (6) Functions and initial scope (Part 2)

php中世界最好的语言
Release: 2018-03-10 13:26:09
Original
1283 people have browsed it

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;
}//不能相互访问
Copy after login

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)

Basics Summary of JavaScript knowledge (5) Brief introduction to array or object typeof, type conversion

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template