Get the App
SLTechnology News&Howtos  ›  Development  › 

Can words be reserved for javascript variable names?

Shulou Source: shulou.com Published: 2022-06-02 16:51:29 09月23日 Update

This article mainly introduces "can javascript variable names retain words?" in daily operation, I believe many people have doubts about whether javascript variable names can retain words. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "javascript variable names can retain words?" Next, please follow the editor to study!

Can not, javascript variable naming rules: 1, can not be keywords, reserved words; 2, can only use letters, underscores or dollar characters, and the first character can not be a number; 3, can not appear Chinese characters, can not contain spaces.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

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

In JavaScript, defining variables requires the use of the var, let, and const keywords, and the syntax format is as follows:

Var variable name; let variable name; const variable name = value

Naming rules for variables

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

Variable names can contain numbers, letters, underscores _, and the dollar sign $

Chinese characters cannot appear in variable names

Variable names cannot contain spaces

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 it can be easily understood by yourself or others. For example, you can use name to define a variable to store the name, and dataArr to define an array type variable.

When the variable name contains multiple English words, it is recommended to use the hump naming method (big hump: the first letter of each word is capitalized, such as FileType, DataArr; hump: the first letter of the first word is capitalized after lowercase, such as fileType, dataArr).

At this point, the study of "can words be retained in javascript variable names" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Variables names letters numbers words learning keywords characters rules humps underscores capitals arrays more spaces symbols Chinese characters storage help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Microsoft OPPO Reno MariaDB