2.1 The Text of a JavaScript Program
JavaScript is a case-sensitive language
JavaScript ignores spaces that appear between tokens in programs.
Whitespace
line terminators
2.2 Comments
JavaScript supports two styles of comments.
//
/*
and */
,
may not be nested
2.3 Literals
A literal is a data value that appears directly in a program.
12 // The number twelve
1.2 // The number one point two
"hello world" // A string of text
‘Hi‘ // Another string
true // A Boolean value
false // The other Boolean value
null // Absence of an object
2.4 Identifiers and Reserved Words
An identifier is simply a name
A JavaScript identifier must begin with a letter, an underscore (_
), or a dollar sign ($
). Subsequent characters can be letters, digits, underscores, or dollar signs.
“reserved words” cannot be used as regular identifiers
2.4.1 Reserved Words
they can all be used as the names of properties within an object
let
can be used as a variable name if declared with var
outside of a class, for example, but not if declared inside a class or with const
.
might be used in future versions:
arguments
and eval
are not allowed as identifiers in certain circumstances
2.5 Unicode
JavaScript programs are written using the Unicode character set
it is common to use only ASCII letters and digits in identifiers
the language allows Unicode letters, digits, and ideographs (but not emojis) in identifiers.
2.5.1 Unicode Escape Sequences
write Unicode characters using only ASCII characters
\UA190, \U{1~6digits}
These Unicode escapes may appear in JavaScript string literals, regular expression literals, and identifiers (but not in language keywords)
Unicode escapes may also appear in comments, they are simply treated as ASCII characters
2.5.2 Unicode Normalization
JavaScript assumes that the source code it is interpreting has already been normalized and does not do any normalization on its own.
2.6 Optional Semicolons
JavaScript uses the semicolon (;
) to separate statements
In JavaScript, you can usually omit the semicolon between two statements if those statements are written on separate lines.
use semicolons to explicitly mark the ends of statements, even where they are not required.
it usually treats line breaks as semicolons only if it can’t parse the code without adding an implicit semicolon
if a statement begins with (
, [
, /
, +
, or -
, there is a chance that it could be interpreted as a continuation of the statement before.
defensive semicolon at the beginning
There are three exceptions:
return
, throw
, yield
, break
, and continue
statements. If a line break appears after any of these words, JavaScript will always interpret that line break as a semicolon.
++
and –
operators=>
arrow itself must appear on the same line as the parameter list.2.7 Summary
This chapter has shown how JavaScript programs are written at the lowest level.
原文:https://www.cnblogs.com/zxk44944/p/14642472.html