JavaScript declares variables with the VAR keyword
var variable name;
Declaration Variable name Considerations:
- The variable name consists of a letter, a value, a "$" symbol, an underscore
- Variable names must begin with a letter, a "$" symbol, or an underscore
- Variable names cannot use JavaScript keywords and reserved words
- Variable names are case-sensitive
Variables must first be declared and then used
var name = "Tom"; var age;age = 10;
When a variable is not assigned a value, the default is undefined, and the variable can be assigned repeatedly.
Variables can hold any type of value, such as numeric value, String, Boolean, etc.
var a = 5;a = "123"; a = true;
Variables can also be directly assigned using the VAR keyword, such as:
i = 5;
Note: This creates a variable in a way that does not conform to the specification and creates a global variable.
JavaScript Basics (2) variables