JavaScript Core language Note-2 syntax structure

Source: Internet
Author: User

Character

The Javassript program is written in the Unicode character set , Unicode is a superset of ASCII and Latin-1, and supports almost all languages in use. ECMAScript 3 requires that JAVASCRIPT implementations must support Unicode 2.1 and subsequent versions, and ECMAScript 5 requires support for Unicode 3 and later versions

Case sensitive

JavaScript is case-sensitive. Keywords, variables, function names, and all identifiers (identifier) must be in a consistent case form

Note that HTML, HTML 5 (label, attribute name) is not case-sensitive, XHTML is case-sensitive, but modern browsers often have fault tolerance, even if the label name, property name capitalization is also normal parsing. Note that the attribute values of HTML tags are case-sensitive, such as

<class= "Warp Warp"></div>

Spaces, line breaks, and formatting control symbols

JavaScript ignores spaces between tokens in the program. In most cases, JavaScript ignores line breaks.

JavaScript will recognize the following whitespace characters

    • Normal empty characters (\u0020)
    • Horizontal tab (\u0009)
    • Vertical tab (\U000B)
    • Page Break (\u000c)
    • Do not break whitespace characters (\u00a0)
    • byte-order tagging (\ufeff)

JavaScript recognizes that the following characters are recognized as line terminators

    • Line Break (\u000a)
    • Carriage return character (\u000d)
    • Row Separator (\u2028)
    • Segment Separator (\u2029)

Carriage return multibyte a newline character is parsed together into a single-line terminator

Unicode Escape Sequences

In some computer hardware and software can not display a complete list of Unicode characters, JavaScript defines a special sequence, using 6 ASCII characters to represent any 16-bit Unicode inside code. These inner codes are prefixed with \u and followed by 4 hexadecimal digits. This Unicode escape notation can be used in JavaScript string literals, direct amounts of regular expressions, and identifiers (except for keywords). For example:

1 "\u4f60\u597d\uff0c\u4e16\u754c" = = = "Hello, world"   //= + true2//Note Because the 4 16 binary numbers behind \u are not case-sensitive, so u Nicode code is not case sensitive 3 "\u4f60\u597d\uff0c\u4e16\u754c" = = = "Hello, world"   //= = True
Comments

Comments like Java and C, multi-line comments cannot be nested//single line,/* */multiple lines;

Direct volume

Direct volume (literal) is the data value that is used directly in the program

1 2//              number 1.2            //decimal number 3' hello '        //String 4True           //Boolean True 5 false          //Boolean false 6 /javascript/gi//Regular Expression Direct volume
Identifiers and reserved words

An identifier (indetifiers) is a name used to name variables and functions, and a JavaScript identifier must start with a letter, underscore (_), or dollar ($) character.

You can also use a complete collection of Unicode characters, such as:

1 var hello = ' you '; 2 varπ= 3.14; 3 Hello                //= "You"4 π                   //= 3.14

The reserved word (Reserved Words) is the identifier that JavaScript uses for its own keyword, and you should avoid using these identifiers to name them when writing programs.

Break Delete function Return typeof case does if switch var catch else in this void continue false instanceof throw while de Bugger finally new true with the default for null try

These keywords are retained in ECMAScript 5, and may be used in the future

Class Const Enum export extends import super

The following keywords are valid in normal JavaScript code, but are reserved words in strict mode:

Implements let private publicly yield interface package protected static

JavaScript defines a number of global variables and functions, to avoid using these names for variable names or function names, such as: Arguments encodeURI JSON Math, etc.

Optional semicolon

Typically, JavaScript statements are separated by semicolons (;), but in most cases the JavaScript parser automatically adds semicolons, so some programmers don't like to add semicolons, which is also possible if the code has the correct writing.

So two semicolons can be omitted

1 var a = 3; 2 var b = 4; 3 //  Such multiple variables comma-separated, with a semicolon J end can be 4  var a=5, b=6, c=4;

JavaScript Core language Note-2 syntax structure

Related Article

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.