Are JavaScript variable names case-sensitive?

藏色散人
Release: 2021-11-18 16:04:33
Original
5115 people have browsed it

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.

Are JavaScript variable names case-sensitive?

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;
Copy after login

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";
Copy after login

You can assign a value to a variable when you declare it:

var carName = "porsche";
Copy after login

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 = &quot;porsche&quot;; document.getElementById("demo").innerHTML = carName; </script>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!