Use of semicolons in ES6 [duplicate]
I was under the impression semicolons became obsolete with ES6. However, I came across this today:
Doesn't work:
let i = 0
[0, 1, 2, 3, 4, 5, 6].forEach(item => console.log(item))
Works:
let i = 0;
[0, 1, 2, 3, 4, 5, 6].forEach(item => console.log(item))
Why is the semicolon necessary here, and when should I use them?
Without the semicolon [1,2,3,4,5,6] will be evaluated as property access. Which is perfectly fine JS, I personally don't think that adding semicolons is such a big deal so I keep using them.