ECMAScript's syntax draws heavily on the syntax of C and other C languages such as Java and Perl.
(1) Case-sensitive
Case sensitivity means that the variable name test and test represent two different variables, respectively. In other words, the keyword, variable, function name, and all identifiers (identifier) must be in a consistent case form.
However, it is important to note that HTML is not case-sensitive (although XHTML is case-sensitive). Because it is closely tied to client-side JavaScript (JavaScript running in a Web browser), this distinction is easily confusing.
Many client-side JavaScript exclusive and attributes have the same name as the HTML tags and attributes they represent. In HTML, these tags and property names can be capitalized or lowercase, while in JavaScript they must be lowercase. For example, when you set an event handler in HTML, the OnClick property can be written as an onclick, but in JavaScript code (or XHTML documents) you must use the lower-case onclick.
(2) Identifiers
The so-called identifier refers to the name of a variable, function, property, or parameter of a function.
The format rules for identifiers are as follows:
- The first character must be a letter, an underscore (_), or a dollar sign ($).
- Other characters can be letters, underscores, dollar signs, or numbers.
- The letters in the identifiers can also contain extended ASCII Unicode alphabetic characters, but we do not recommend this.
The JavaScript identifiers are in hump-case format, which is the first lowercase letter, with the first letter capitalized for each of the remaining words.
While no one enforces this format, it can be used as a best practice in order to be consistent with JavaScript's built-in function and object naming format.
(3) statement
The statements in JavaScript end with a semicolon, and the parser determines the end of the statement if the semicolon is omitted. Although the semicolon at the end of the statement is not required, we recommend that you do not omit it at any time.
(4) Keywords and reserved words
Both keywords and reserved words cannot be used as identifiers.
JavaScript describes a set of keywords that have a specific purpose, according to the rules, the keywords are also language reserved and cannot be used as identifiers. JavaScript also describes another set of reserved words that cannot be used as identifiers, although reserved words do not have any specific purpose in the language, but they may be used in the future as keywords.
(5) Notes
JavaScript uses C-style annotations, including single-line comments and block-level annotations. A single-line comment begins with two slashes, as follows:
Single-line Comment
Block-level comments begin with a slash and an asterisk (*), ending with an asterisk and a slash, as follows:
/*
* This is a multi-line (block-level) Comment
*/
Although the second line in the above comment starts with an asterisk, this is not required. The asterisk is added purely to improve the readability of the annotations.
JavaScript Learning (iv): JavaScript syntax