Home >Web Front-end >JS Tutorial >JS data structure
The content shared with you in this article is about the data structure of js, which has certain reference value. Friends in need can refer to it
Identifier, to put it bluntly, is just a name. In JavaScript, variables and functions need to be defined with a name, which can be called an "identifier".
The three most important points of identifiers in the JavaScript language are:
(1)第一个字符必须是字母、下划线(_)或美元符号这3种其中之一,其后的字符可以是字母、数字或下划线、美元符号; (2)变量名不能包含空格、加号、减号等符号; (3)标识符不能和JavaScript中用于其他目的的关键字同名;
These points are the same as the naming rules of many other languages such as C and Java.
JavaScript keywords refer to those words that have specific meanings in the JavaScript language and become part of the JavaScript syntax. JavaScript keywords cannot be used as variable names and function names, which means that the name of a variable or function cannot have the same name as a system keyword. Using JavaScript keywords as variable names or function names will cause JavaScript compilation errors during the loading process.
At this point, JavaScript is the same as other programming languages.
Constants, as the name suggests, refer to quantities that cannot be changed. The meaning of constant is fixed from the beginning of definition until the end of the program.
Constants are mainly used to provide fixed and precise values for programs, including numerical values and strings, such as numbers, logical values true (true), logical values false (false), etc. are all constants.
Variables, as the name suggests, mean that their values can be changed during the running of the program.
The name of a variable is actually an identifier, so when naming a variable, you must also follow the naming rules of identifiers:
(1) The first character must be a letter, underscore (_) or dollar sign, and the subsequent characters can be letters, numbers, underscores, or dollar signs;
(2) The variable name cannot contain spaces, plus signs, or minus signs. and other symbols;
(3) Identifiers cannot have the same name as keywords used for other purposes in JavaScript;
in JavaScript , variables need to be declared before using them.
Remember one thing:
"All JavaScript variables are declared by the keyword var".
At this point, JavaScript is different from C and Java.
Syntax:
var variable name;
var variable name=value;
Instructions:
While declaring a variable, you can also assign a value to the variable.
A keyword var can also declare multiple variable names at the same time. The variable names must be separated by English commas ",". For example, declare variables name, age, and gender to represent name, age, and gender respectively. The code is as follows:
var name,age,gender;
You can assign values to variables while declaring them:
var name="Zhang San", age=18; gender="male";
It is best to declare the required variables at the beginning of the code
The scope of a variable refers to the valid range of a variable in the program, that is, the area in the program where the variable is defined. In JavaScript, variables can be divided into two types according to their scope: global variables and local variables.
Global variables are defined in the main program, and their valid range is from the beginning of definition to the end of this program. Local variables are defined in the function of the program, and their valid scope is only within the function; when the function ends, the local variable lifetime ends.
Identifier, to put it bluntly, is a name. In JavaScript, variables and functions need to be defined with a name, which can be called an "identifier".
The three most important points of identifiers in the JavaScript language are:
(1)第一个字符必须是字母、下划线(_)或美元符号这3种其中之一,其后的字符可以是字母、数字或下划线、美元符号; (2)变量名不能包含空格、加号、减号等符号; (3)标识符不能和JavaScript中用于其他目的的关键字同名;
These points are the same as the naming rules of many other languages such as C and Java.
JavaScript keywords refer to those words that have specific meanings in the JavaScript language and become part of the JavaScript syntax. JavaScript keywords cannot be used as variable names and function names, which means that the name of a variable or function cannot have the same name as a system keyword. Using JavaScript keywords as variable names or function names will cause compilation errors during JavaScript loading.
At this point, JavaScript is the same as other programming languages.
Constants, as the name suggests, refer to quantities that cannot be changed. The meaning of constant is fixed from the beginning of definition until the end of the program.
Constants are mainly used to provide fixed and precise values for programs, including numerical values and strings, such as numbers, logical values true (true), logical values false (false), etc. are all constants.
Variables, as the name suggests, mean that their values can be changed during the running of the program.
The name of a variable is actually an identifier, so when naming a variable, you must also follow the naming rules of identifiers:
(1) The first character must be a letter, underscore (_) or dollar sign, and the subsequent characters can be letters, numbers, underscores, or dollar signs;
(2) The variable name cannot contain spaces, plus signs, or minus signs. Symbols such as numbers;
(3) Identifiers cannot have the same name as keywords used for other purposes in JavaScript;
In JavaScript, variables need to be declared before using them.
Remember one thing:
"All JavaScript variables are declared by the keyword var".
At this point, JavaScript is different from C and Java.
Syntax:
var variable name;
var variable name=value;
Instructions:
While declaring a variable, you can also assign a value to the variable.
A keyword var can also declare multiple variable names at the same time. The variable names must be separated by English commas ",". For example, declare variables name, age, and gender to represent name, age, and gender respectively. The code is as follows:
var name,age,gender;
You can assign values to variables while declaring them:
var name="Zhang San", age=18; gender="male";
It is best to declare the required variables at the beginning of the code
The scope of a variable refers to the valid range of a variable in the program, that is, the area in the program where the variable is defined. In JavaScript, variables can be divided into two types according to their scope: global variables and local variables.
Global variables are defined in the main program, and their valid range is from the beginning of definition to the end of this program. Local variables are defined in the function of the program, and their valid scope is only within the function; when the function ends, the local variable lifetime ends.
Related recommendations:
Detailed explanation of arrays and hash tables of js data structures and algorithms
Stacks and queues of js data structures and algorithms Detailed explanation
The above is the detailed content of JS data structure. For more information, please follow other related articles on the PHP Chinese website!