2Answers
What enhances the readability of the code is ignored by the JavaScript interpreter when parsing the program.
Asked by: Walter Wright 249 views IT
What enhances the readability of the code is ignored by the JavaScript interpreter when parsing the program.
+6Votes
Blank (WhiteSpace)
Blanks usually don’t make sense, sometimes you have to use them to separate character sequences, otherwise they will be merged into a single symbol
var that = this;
The gap between var and that cannot be removed, but other whitespace can be removed
javascript ignores spaces between tokens in the program. . In most cases, javascript will also ignore newline characters. Since you can use spaces and line breaks in your code, you can use a neat, consistent indentation to form a uniform coding style to improve the readability of the code
javascript will be as follows These are recognized as whitespace characters WhiteSpace
\u0009 Horizontal Tabs<TAB>\u000B Vertical Tabs<VT>\u000C Page Breaks<FF>\u0020 Space Characters<SP> \u00A0 Non-interrupted space character <NBSP>\uFEFF character sequence tag
javascript recognizes the following character as line terminator LineTerminator
\u000A newline character <LF>\ u000D Carriage Return <CR>\u2028 Line Separator <LS>\u2029 Paragraph Separator <PS>
Optional Semicolon
javascript uses a semicolon; Separating the statements is very important to enhance the readability and cleanliness of the code. However, javascript does not fill the semicolon at all newlines. Only when the code is missing can’t parse the code correctly, javascript will fill the semicolon
var aa=3console.log(a)
javascript parses it as:
var a;a = 3;console.log(a);
The separation rule for this statement will Lead to some unexpected situations
var y = x + f(a+b).toString
javascript parses it to:
var y = x + f(a+b).toString
Therefore, in order to resolve the above code into two different statements, you must manually fill in the explicit semicolon at the end of the line
Two exceptions
If the current statement and the next statement cannot be merged, javascript will fill the semicolon after the first line. This is a general rule, but there are two exceptions
1] The first exception is in scenarios involving return, break, continue, and throw statements. If these four keywords are followed by a newline, javascript will fill the semicolon at the newline
returntrue;
javascript parses it to:
return;true;
and the original meaning of the code is:
return true;
[2] The second exception is in the case of + The + and — operators, if used as a postfix expression, should be on the same line as the expression. Otherwise, the end of the line will fill the semicolon, and ++ or — will be used as the prefix operator for the next line of code and parsed together
x++y
javascript will Its resolution is:
x;++y;
and the original meaning of the code is:
x++;y;
Although the semicolon is not required, it is best not to omit it, because adding a semicolon can avoid many errors, and there is no semicolon at the end of the line to cause a compression error. Adding a semicolon will also improve the performance of the code in some cases, because the parser does not have to spend time speculating where to insert the semicolon.
+8Votes
single-line comments and multi-line comments. Single line comments are indicated by a double backslash “//”. When a line of code has “//”, then the part after “//” will be ignored. Multi-line comments are one-to-many lines enclosed in “/*” and “*/”. When the program is executed to “/*”, all subsequent words will be ignored until “*/” appears.