Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  13] [ 4]  / answers: 1 / hits: 37508  / 9 Years ago, fri, january 22, 2016, 12:00:00

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?


More From » node.js

 Answers
56

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.


[#63607] Wednesday, January 20, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mahogany

Total Points: 645
Total Questions: 107
Total Answers: 98

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
mahogany questions
;