let x = 10 let y = 20 console.log(x+y)//3
If written on the same line, you must add a semicolon:
let x, y x = 10 y = 30 console.log(x+y)//SyntaxError: Unexpected identifier
Do not write a semicolon to report an error.
The following example:
let a a = 3 console.log(a)//3
Obviously, the code is parsed as:
let a; a=3; console.log(a);
No semicolons are inserted in 2 or 3 rows.
The separation rules of these statements will lead to some unexpected situations, such as the following example;
let m = n + f (b+c).toString()
But the statement will eventually be parsed as:
let m = n + f(a+b).toString();
This is inconsistent with the meaning expressed by the source code, but there is no error when it is parsed.
In layman's terms, if a sentence starts with "(", "[", "/", "+", "-", they are most likely to be parsed together with the previous sentence.
However, there are 2 exceptions,
If return, break, continue are involved, if these three keywords are followed by a newline, a semicolon must be inserted after the keyword;
Will be parsed into
This obviously violates the original intent of the code.
If the "++" and "--" operators are involved, these expressions can be used as the prefix or suffix of the expression.
x ++ y
This code parses as: