The lexical structure of a programming language is a set of basic rules that describe how to use the language to write programs.
1. Character SetJavaScript programs are written in the Unicode character set.
1.1 Case-sensitiveJavaScript is a case-sensitive language. In other words, the keyword, variable, function name, and all identifiers (identifier) must be in a consistent case form. For example, "name" and "name" are different variables.
1.2 spaces, line breaks, and format controlsIn JavaScript, spaces between identities in the program are ignored. For newline characters, JavaScript is ignored in most cases, but there is one exception: when you add a line break after a return, break, continue statement, JavaScript adds a semicolon at the line break. JavaScript can recognize some special characters:
Whitespace (\u0020) Horizontal tab (\u0009) page break (\u000c) newline character (\u000a) carriage return (\u000d)
Carriage return multibyte The newline character together is resolved to a single-line terminator.
1.3 Unicode escape sequenceJavaScript 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)
2. CommentsJavaScript provides comments in two formats. Single-line Comment: Start multiple lines of comments with//: put between/* and/* (can be written across lines, but not nested annotations)
3. Direct VolumeDirect Volume: The data value that is used directly in the program. Like what:
//Digital
1.2//decimal
"Hello World"//String
True//Boolean value
/javascript/gi //Regular expression Direct volume
Null // NULL
4. Identifiers and reserved WordsAn identifier (identifier) is a name used to identify a specific object. The identifier for the JavaScript language is case sensitive, so a and a are two different identifiers.
identifier naming rules:The first character cannot be a number, it can be any Unicode letter (including letters in English letters and other languages), and the second and subsequent characters of the dollar sign ($) and underscore (_), in addition to Unicode letters, dollar signs, and underscores, you can also use numbers. Chinese is a valid identifier and can be used as a variable name. JavaScript has reserved words that cannot be used as identifiers: arguments, break, case, Catch, class, Const, continue, debugger, default, delete, do, else, enum, Eval, export, extends, false, finally, for, function, if, implements, import, in, instanceof, interface, let, new, NULL, Package, private, protected, public, return, static, super, switch, this, throw, true, try, typeof, Var, void, while, with, Yield In addition, there are three words that are not reserved words, but because they have special meanings, they should not be used as identifiers: Infinity, NaN, undefined.
5. Optional semicolonJavaScript separates the statements by using semicolons (;).Note:JavaScript does not fill the semicolon at all line breaks, and the semicolon is filled only if the code is not parsed correctly when the semicolon is missing. It can also be said 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. For example, the following code:
var a
A
=
3
Console.log (a)
javascript resolves it to:
var a;a=3; Console.log (a);
JavaScript adds a semicolon to the first line of line breaks, because without a semicolon, JavaScript cannot parse the code var a. The second a can be treated as a single statement "A;", but JavaScript does not fill the second line with a semicolon because it resolves to "a=3" with the third line of content. The above code is no problem after parsing, but not actively add semicolons, and sometimes lead to unexpected situations. Like what:
var y=x+f
(a+b). ToString ()
After parsing:
var y=x+f (a+b). toString ();
If the current statement and the next line of statements cannot be parsed, JavaScript fills the semicolon after the first line, which is a general rule, with two exceptions.
The first exception is when the scenario involving return, break, and continue statements is total, and if the three keywords are followed by a newline, JavaScript fills the semicolon at the line break.
For example:
Return
True
JavaScript will parse into:
Return true;
The second exception is when the "+ +" and "---" operators are involved.
X
++
Y
will be parsed as "x;++y" instead of "x++;y"
Add semicolons as appropriate to avoid unexpected errors.
Copyright belongs to the author.
Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Original: Http://ghmagical.com/article/page/id/5H9adupu2pDY? Ghmagical.com
JavaScript Learning Notes