Home > Article > Web Front-end > Are JavaScript variable names case-sensitive?
Javascript variable naming is case-sensitive. All JavaScript variables must be identified by unique names. These unique names are called identifiers; identifiers can be short names or more descriptive names.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
Are JavaScript variable names case-sensitive?
Javascript variable naming is case-sensitive.
JavaScript variables are containers that store data values.
JavaScript Identifiers
All JavaScript variables must be identified by a unique name.
These unique names are called identifiers.
Identifiers can be short names (such as x and y), or more descriptive names (age, sum, totalVolume).
The general rules for constructing variable names (unique identifiers) are:
Names can contain letters, numbers, underscores, and dollar signs
The name must start with a letter
The name can also start with $ and _ (but we won’t do that in this tutorial)
Names are case-sensitive (y and Y are different variables)
Reserved words (such as JavaScript keywords) cannot be used as variable names
Tip: JavaScript identifiers are case-sensitive.
Assignment Operator
In JavaScript, the equal sign (=) is the assignment operator, not the "equals" operator.
Note: The "equal" operator in JavaScript is ==.
Declaring (Creating) JavaScript Variables
Creating a variable in JavaScript is called "declaring" a variable.
You can declare JavaScript variables through the var keyword:
var carName;
After declaration, the variable has no value. (Technically, its value is undefined.)
To assign a value to a variable, use the equal sign:
carName = "porsche";
You can assign a value to a variable when you declare it:
var carName = "porsche";
In the above example, we created a variable named carName and assigned the value "porsche" to it.
Then, we "output" the value in the HTML paragraph with id="demo":
Example
<script> var carName = "porsche"; document.getElementById("demo").innerHTML = carName; </script>
Recommended learning:《javascript basic tutorial》
The above is the detailed content of Are JavaScript variable names case-sensitive?. For more information, please follow other related articles on the PHP Chinese website!