Variables
What is a variable? Literally, a variable is a variable amount; from a programming perspective, a variable is used to A memory that stores certain/certain values
1. JS is a weak data type language; that is, when defining variables, just use var to represent them, or even not write them.
2. The variable data type in js is determined by the js engine
How to define variables, the syntax format is as follows:
var variable name;
Example:
var a; var b;
In this way we define two variables a and b
The variable names can Name it arbitrarily, but follow the naming rules:
1. Variables must start with a letter, underscore (_) or dollar sign ($).
2. Then you can use any number of English letters, numbers, underscores (_) or dollar signs ($).
3. JavaScript keywords and JavaScript reserved words cannot be used.
How to assign a value to a variable
There are two ways to assign a value to a variable
The first one:
var a;
a = 123456;
Second type:
var a=123456;
Variables can be assigned repeatedly
Please see the example, the following code
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>javascript</title> </head> <body> <script type="text/javascript"> var a=123456; var a=189; document.write(a); </script> </body> </html>
Note:
1. JS is case sensitive, if the variable a is different from A, it means two variables.
2. Although variables can be used directly without declaring them, they are not standardized and need to be declared first and then used.