Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the function of var in javascript

Shulou Source: shulou.com Published: 2022-06-03 05:08:34 10月17日 Update

This article introduces the relevant knowledge of "what is the role of var in javascript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Var in javascript is a keyword used to define variables, functions, objects, etc., and all variables in JavaScript can be defined by the var keyword.

This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.

What is var in javascript?

Var is a keyword in javascript that defines variables, functions, objects, and so on. All variables in JavaScript can be defined by the var keyword.

The creation of a JavaScript variable is also called a "declaration" variable:

Var carName

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

Assign a value to the variable as follows:

CarName = "Volvo"

When you declare a variable, you can also assign a value to it:

Var carName = "Volvo"

Var key definition functions can be done in this way:

Var function name = function () {function body}

Of course, js defines functions in more than just the above way, so I won't repeat them here.

In addition, you can use var to define objects in the format:

Var object name = {member variable 1: member value, member variable 2: member value, member variable 3: member value,... }

Note: in JavaScript, reserved words and keywords cannot be used as identifiers, that is, they cannot be used as names of variables or functions. Keywords are words that have been defined as having special functions in JavaScript, such as to indicate the beginning or end of a control statement.

This is the end of the content of "what is the role of var in javascript". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Variable key function keyword member object function content way more knowledge accessible practical special learned and then not only that is function only Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology MariaDB vpn Xiaomi