Javascript is identified by starting with a letter, underscore "_" or dollar sign "$"; subsequent characters can also be numbers, and because the JavaScript language is case-sensitive, letters can start from " Uppercase letters from A" to "Z" and lowercase letters from "a" to "z".
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
What does javascript use to identify?
Basics
JavaScript borrows much of its syntax from Java, but is also influenced by Awk, Perl and Python.
JavaScript is case-sensitive and uses the Unicode character set. For example, you can use the word Früh (meaning "morning" in German) as a variable name.
var Früh = "foobar";
However, since JavaScript is case-sensitive, the variables früh and Früh are two different variables.
In JavaScript, instructions are called statements and are separated by semicolons (;).
If a statement occupies one line, the semicolon can be omitted. (Translator's Note: This is not recommended.) But if there are multiple statements in one line, then these statements must be separated by semicolons. ECMAScript provides for automatic semicolon insertion (ASI) at the end of statements. (If you want to learn more, see JavaScript Lexical Syntax .) Although not required, it is a good habit to include a semicolon at the end of a statement. This habit can greatly reduce the possibility of bugs in your code.
Javascript source code is scanned from left to right and converted into a series of input elements consisting of tokens, control characters, line terminators, comments and whitespace characters. Whitespace characters refer to spaces, tabs, newlines, etc.
Variables
In applications, variables are used as symbolic names for values. The name of a variable is also called an identifier, and it needs to follow certain rules.
A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be numbers (0-9). Because the JavaScript language is case-sensitive, letters can be uppercase letters from "A" to "Z" and lowercase letters from "a" to "z".
You can use most ISO 8859-1 or Unicode-encoded characters as identifiers, such as å and ü (see this blog post for details). You can also use Unicode escape characters as identifiers.
Examples of legal identifiers: Number_hits, temp99, $credit and _name.
Declaring variables
You can declare variables in the following three ways:
Use the keyword var. For example var x = 42. This syntax can be used to declare local variables and global variables.
Direct assignment. For example x = 42. Using this form of assignment outside a function will create a global variable. An error will occur in strict mode. Therefore you should not declare variables this way.
Use keyword let . For example let y = 13. This syntax can be used to declare block-scoped local variables. See Variable scope below.
Recommended study: "javascript Advanced Tutorial"
The above is the detailed content of What does javascript use to identify. For more information, please follow other related articles on the PHP Chinese website!