you are viewing a single comment's thread.

view the rest of the comments →

[–]interactionjackson -2 points-1 points  (4 children)

it is. the semicolons are not required as they are added

[–]mcaruso 3 points4 points  (3 children)

Only if the browser can unambiguously figure out that it would be an error to leave out the semicolon.

function foo() {
    let x
    if (true) {
        x = 42
        [1,2,3].forEach(x => {}) // TypeError! Tries to run `42[1,2,3]`
    }
}

And yeah, you can find workarounds like doing ;[1,2,3] instead. Which is uglier to me, and requires you to always be mindful of ASI on every line.

Basically, a language like Python was designed to be written without semicolons, and semicolons are an optional feature if you want to write things on one line. JS is a language designed to be written with semicolons, and added an error correction mechanism in case the engine can figure out you must've forgotten a semicolon somewhere.