var in javascript is a keyword used to define variables, functions, objects, etc., and all variables in JavaScript can be defined through the var keyword.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
What is var in javascript?
var is a keyword in JavaScript, used to define variables, functions, objects, etc. All variables in JavaScript can be defined through the var keyword.
The creation of JavaScript variables is also called "declaring" variables:
var carName;
After a variable is declared, the variable is empty (no value).
Assign a value to a variable. The operation is as follows:
carName = "Volvo";
When declaring a variable, you can also assign a value to the variable:
var carName = "Volvo";
The var key definition function can be defined in this way:
var 函数名 = function(){函数体}
Of course, there are more than just the above ways to define functions in js, so I won’t go into details here.
In addition, you can also use var to define objects, the format is:
var 对象名 ={成员变量1:成员值, 成员变量2:成员值, 成员变量3:成员值, ……};
Note: In JavaScript, reserved words and keywords cannot be used as identifiers, that is, they cannot be used as variables or The name of the function. Keywords are words that have been defined in JavaScript as having special functions, such as being used to indicate the beginning or end of a control statement.
[Recommended learning: javascript basic tutorial]
The above is the detailed content of What is var in javascript. For more information, please follow other related articles on the PHP Chinese website!