How to declare the JavaScript variable
This article mainly explains "how to declare JavaScript variables". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to declare JavaScript variables.
One statement, multiple variables
You can declare many variables in one statement. The statement begins with var and uses commas to separate variables:
Varlastname= "Doe", age=30,job= "carpenter"
Declarations can also span multiple lines:
Varlastname= "Doe"
Age=30
Job= "carpenter"
Multiple variables declared in a statement cannot be assigned the same value at the same time:
Varx,y,z=1
XQuery y is undefined,z is 1.
Value=undefined
In computer programs, variables with no value are often declared. A variable that is not declared with a value whose value is actually undefined.
After executing the following statement, the value of the variable carname will be undefined:
Varcarname
Redeclare the JavaScript variable
If you redeclare the JavaScript variable, the value of the variable is not lost:
After the following two statements are executed, the value of the variable carname is still "Volvo":
Varcarname= "Volvo"
Varcarname
JavaScript arithmetic
You can do the math through the JavaScript variable, using operators such as = and +:
Example
Yellow5
X=y+2
At this point, I believe you have a deeper understanding of "how to declare JavaScript variables". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!