The return statement is part of some javascript statements that must be terminated with semicolons and is therefore affected by automatic semicolon insertion (ASI) along with others like (continue, import, let, const e.t.c)
There are 3 rules for the ASI, but I think the one you're looking for is this
"A semicolon is inserted at the end when the end of the input stream of tokens is detected and the parser is unable to parse the single input stream as a complete program".
Interesting! So since return is a keyword that must end with a semicolon, a semicolon is placed. But because return x ends with an identifier, it checks the next line to see if it is parsable as a program, and if it is, then it doesn't insert a semicolon. Neat!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The
return
statement is part of some javascript statements that must be terminated with semicolons and is therefore affected by automatic semicolon insertion (ASI) along with others like (continue
,import
,let
,const
e.t.c)There are 3 rules for the ASI, but I think the one you're looking for is this
"A semicolon is inserted at the end when the end of the input stream of tokens is detected and the parser is unable to parse the single input stream as a complete program".
View the rest at developer.mozilla.org/en-US/docs/W...
Interesting! So since
return
is a keyword that must end with a semicolon, a semicolon is placed. But becausereturn x
ends with an identifier, it checks the next line to see if it is parsable as a program, and if it is, then it doesn't insert a semicolon. Neat!