Can't JavaScript variable names be reserved words?

青灯夜游
Release: 2021-11-08 17:40:40
Original
2656 people have browsed it

No, the naming rules for JavaScript variables: 1. They cannot be keywords or reserved words; 2. Only letters, underscores or dollar signs can be used, and the first character cannot be a number; 3. Chinese characters cannot appear , cannot contain spaces.

Can't JavaScript variable names be reserved words?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Variables are one of the foundations of all programming languages. They can be used to store data, such as strings, numbers, Boolean values, arrays, etc., and set, update or read the contents of the variables when needed. We can think of a variable as a symbolic name for a value.

In JavaScript, you need to use the var, let and const keywords to define variables. The syntax format is as follows:

var 变量名;
let 变量名;
const 变量名=值;
Copy after login

Naming rules for variables

In JavaScript, variable names cannot be defined casually and need to follow the naming rules of identifiers, as shown below:

  • Variable names can contain numbers, letters, underscores_, and dollars. Symbol $;

  • Chinese characters cannot appear in the variable name;

  • The variable name cannot contain spaces;

  • The variable name cannot be a keyword or reserved word in JavaScript;

  • The variable name cannot start with a number, that is, the first character cannot be a number.

When defining a variable, the variable name should be as meaningful as possible so that you or others can easily understand it. For example, you can use name to define a variable that stores names, and dataArr to define a variable that stores names. Variable of array type.

When the variable name contains multiple English words, it is recommended to use camel case naming (big camel case: the first letter of each word is capitalized, such as FileType, DataArr; small camel case: the first letter of the first word is lowercase and the following Capitalize the first letter of a word, such as fileType, dataArr).

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of Can't JavaScript variable names be reserved words?. 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!