Questions about optional semicolons in the authoritative guide to js

original

JavaScript does not fill in semicolons at all line breaks: JavaScript fills in semicolons only if the code cannot be parsed correctly without a semicolon.

demo

var b = 1
var foo = 2
var a = b + foo
(123)
// foo is not a function

but there is no filling in the semicolon. Why didn"t you add a semicolon to it? What"s wrong with my understanding?

Mar.01,2021

foo is an identifier. The browser parses to the next line with parentheses, which is considered to be a function call, and then your foo is not a function

.
Menu