Home >Web Front-end >Front-end Q&A >What are the legal identifiers of JavaScript?

What are the legal identifiers of JavaScript?

WBOY
WBOYOriginal
2022-03-28 16:42:004628browse

The legal identifier representation of JavaScript is: 1. The first character must be a letter, underscore or dollar sign; 2. The identifier cannot have the same name as other keywords in JavaScript; 3. Other characters in the identifier Characters can consist of letters, underscores, dollar signs, and numbers.

What are the legal identifiers of JavaScript?

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What are the legal identifiers of JavaScript

Identifier: In JS, everything that can be named by us can be called an identifier.

For example: variable names, function names, and attribute names are all identifiers.

Naming rules for identifiers in JavaScript language:

  • is case-sensitive, Myname and myname are two different identifiers.

  • The first character of the identifier can start with an underscore (_), a dollar sign ($), or a letter, but cannot be a number.

  • Other characters in the identifier can be underscores (_), dollar signs ($), letters or numbers

  • The identifier cannot have the same name as a keyword used for other purposes in JavaScript

Example: userName, User_Name, _sys_val, height, $change, etc. are all legal identifiers, while 2mail, room #, class is an illegal identifier. Among them, variables named using the Chinese "height" are legal.

Note: The letters in JavaScript use Unicode. Unicode is called the Unified Encoding System, which is an internationally accepted 16-bit encoding system. It includes Asian character encodings, such as Chinese, Japanese, Korean and other characters. All letters in JavaScript can be Asian letters such as Chinese, Japanese, and Korean.

Related recommendations: javascript learning tutorial

The above is the detailed content of What are the legal identifiers of JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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