JavaScript Definitive Guide Sixth edition learning

Source: Internet
Author: User

Chapter II Grammatical structure

2.1 Character Set

What is a character set? What is the relationship between various character sets? What's the relationship with Unicode,utf-8?

Characters (Character) are all kinds of words and symbols, including the national text, punctuation, graphic symbols, numbers and so on. The character set (Characterset) is a collection of multiple characters, with a variety of character sets, each with a different number of characters, a common character set name: The ASCII character set, the GB2312 character set, the BIG5 character set, the GB18030 charset, the Unicode character set, and so on. Http://baike.sogou.com/v291629.htm

The emergence of various character sets in order to meet different regions, different languages, the use of different environments.

Http://www.cnblogs.com/skynet/archive/2011/05/03/2035105.html This connection details the character set and character encoding.

Unicode is a character set, and Utf-32/utf-16/utf-8 is a three character encoding scheme.

2.11 Case

In the front-end, HTML is case-insensitive, but JS is case-sensitive, meaning that keywords, variables, function names, and all identifiers must be in a consistent case.

2.12 spaces, line breaks, and format controls

Token: In the first few lessons SNL reported that token was heard at the time, then checked, temporarily understood as a password-type string. Often used in session validation or other verification, is attached to the main information of a section of characters, to achieve the purpose of verification.

JS will automatically ignore all the spaces and line breaks, so that the code can be indented.

2.13 Unicode escape sequence

  

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. These Unicode escape sequences are prefixed with \u followed by 4 hexadecimal digits (denoted by a number and uppercase or lowercase letters a~f). This Unicode escape notation can be used in JavaScript string literals, direct amounts of regular expressions, and identifiers (except for keywords). For example, the Unicode escape for character é is written as \u00e9, and the following two JavaScript strings are exactly the same:

Unicode escape notation can also appear in comments, but because JavaScript ignores annotations, they are only treated as ASCII characters in the context and are not parsed to their corresponding Unicode characters.

2.2 Notes

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.

  

var a = null;//a is a variable var a = null;/*   A is a variable */

To form a good annotation habit is one of the necessary qualities of a programmer, single-line comment front space, multiline variable start line and end Line no comment content, the middle of each note is a * beginning, tangent attention indentation. As follows

/* * A is a variable */

2.3 Direct Volume

The so-called direct volume is the data value that is used directly in the program, including numbers, strings, Boolean values, expressions, arrays, objects, and so on. Http://www.cnblogs.com/coolicer/archive/2010/10/14/1851173.html

2.4 Identifiers and reserved words

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. JavaScript identifiers must begin with a letter, underscore (_), $, followed by letters, numbers, $, _, (numbers are not allowed to appear as initial letters, so that numbers and identifiers are distinguished)

For portability and ease of writing, we typically use only ASCII letters and numbers to write identifiers. Note, however, that JavaScript allows letters and numbers in the Embox set of Unicode characters to appear in the identifier. (technically, the ECMAScript standard also allows the MN class, MC class, and PC class in the Unicode character set to appear after the first character of the identifier 7). As a result, programmers can also use non-English language or mathematical symbols to write identifiers:

var true ;   var

Reserved words. JavaScript takes some identifiers for its own keywords. Therefore, these keywords can no longer be used as identifiers in the program:

 Break   Delete  function    return  typeof   Case     Do  if  Switch  var  Catch   Else    inch   This    void  Continue    false   instanceof  Throw    while  Debugger    finally     New     true     with  default  for NULL    Try 

It is noteworthy that: this, with _this instead, New,do,continue,delete,debugger and so error prone. Direct definition will error: unexpected token

Http://book.51cto.com/art/201206/343060.htm about other reserved words.

2.5 Optional semi-colons

JS in the semicolon can be omitted, the resolution will be automatically filled. The principle of newline read parsing is that if the current statement and subsequent non-whitespace characters cannot be parsed as a whole, JavaScript fills the semicolon at the end of the current statement line.

Here are a few special notes:

1, if a statement begins with "(", "[", "/", "+" or "-", then it is most likely to be parsed together with the previous statement. Statements that start with "/", "+" and "-" are uncommon, and statements that start with "(" and "[" are very common, at least in some JavaScript coding styles. 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 deleted by mistake, the current statement will parse correctly

2, two exceptions:

The first exception is in a scenario involving return, break, and Continue statements (see Chapter 5th). If the three keywords are followed by a newline, JavaScript fills the semicolon at the line break. For example, this code:

      1. Return
      2. True

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 "+ +" or "--" will be parsed as the prefix operator for the next line of code, for example, this code:

      1. X
      2. ++
      3. Y

This code will parse to "x; ++y ", not" x + +; Y ".

JavaScript Definitive Guide Sixth edition learning

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.