Note | JavaScript authoritative Guide [Sixth edition] Chapter 2nd: Lexical structure

Source: Internet
Author: User

The syntax structure provides rules such as what the variable name is, how to write the comment, and how the program statements are delimited. This chapter introduces the lexical structure of JavaScript in a short space. 2.1. Character SetJavaScript programs are written in the Unicode character set. Unicode is a superset of ASCII and Latin-1, and supports almost all of the languages in use on Earth. 2.1.1, case-sensitive  JavaScript is a case-sensitive language. 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). 2.1.2, spaces, line breaks, and format controlsJavaScript ignores the space between the logo (token) in the program [figure]. In most cases, JavaScript also ignores line breaks (Section 2.5 mentions an unexpected scenario). 2.1.3, Unicode escape sequences  In some computer hardware and software, a complete collection of Unicode characters cannot be displayed or entered. To support programmers who use older technologies, JavaScript defines a special sequence that uses 6 ASCII characters to represent any 16-bit Unicode inner code. 2.2. Comments  JavaScript supports annotations in two formats. Text after "//" at the end of a line is ignored by JavaScript as a comment. In addition, the text between "/*" and "* *" also acts as a comment, which can be written across lines, but cannot have nested annotations. 2.3. Direct VolumeThe so-called direct volume (literal) is the data value that is used directly in the program. 2.4. Identifiers and reserved WordsAn identifier is a name. In JavaScript, identifiers are used to name variables and functions, or as tags for jumping positions in some of the loop statements in JavaScript code. The JavaScript identifier must begin with a letter, an underscore (_), or a dollar ($) character. Subsequent characters can be letters, numbers, underscores, or dollar characters (numbers are not allowed to appear as first characters, so that JavaScript can easily divide identifiers and numbers). For portability and ease of writing, we typically use only ASCII letters and numbers to write identifiers. JavaScript takes some identifiers for its own keywords.  Therefore, you can no longer use these keywords as identifiers in your program: JavaScript also retains some keywords that are not used in the current language version, but may be used in future versions. is legal in normal JavaScript code, but is reserved in strict mode: implements let private public yield interface Package protected staticStrict mode also restricts the use of the following identifiers, which are not entirely reserved words, but cannot be used as variable names, function names, or parameter names: Arguments evalJavaScript pre-defines a number of global variables and functions and should avoid having their names used as variable names and function names: 2.5. Optional semicolonLike many other programming languages, JavaScript uses semicolons (;) to separate statements (see Chapter 5th). This is important to enhance the readability and cleanliness of your code. It is important to note that JavaScript does not fill the semicolon at all line breaks: JavaScript fills the semicolon only if the code is not parsed correctly when the semicolon is missing. Generally speaking, if a statement starts with a "(", "[", "/", "+" or "-", it is most likely to be parsed together with the previous statement. Some programmers prefer to keep a semicolon in front of the statement so that even if the previous statement is modified and the semicolon is mistakenly deleted, the current statement will parse correctly. But there are two exceptions. The first exception is that there can be no line breaks between return, break, and continue and subsequent expressions. The second exception is when the "+ +" and "--" operators are involved (see section 4.8). These operators can be either prefixed to an expression or as a suffix of an expression. If you use it as a suffix expression, it should be on the same line as the expression. Otherwise, the end of the line fills the semicolon, and the "+ +" or "--" will be parsed as the prefix operator for the next line of code. PS: Books with source code --Http://pan.baidu.com/s/1miPlefY

Note | JavaScript authoritative Guide [Sixth edition] Chapter 2nd: Lexical structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.