What is var in javascript

藏色散人
Release: 2021-10-15 14:47:06
Original
6226 people have browsed it

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.

What is var in javascript

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;
Copy after login

After a variable is declared, the variable is empty (no value).

Assign a value to a variable. The operation is as follows:

carName = "Volvo";
Copy after login

When declaring a variable, you can also assign a value to the variable:

var carName = "Volvo";
Copy after login

The var key definition function can be defined in this way:

var 函数名 = function(){函数体}
Copy after login

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:成员值, ……};
Copy after login

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!

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