0

Every example of forEach I can find is written like:

const arr = ['A','B','C']

arr.forEach((letter)=>{
 //do stuff
})

Is it bad practice to do it this way instead?:

;['A','B','C'].forEach((letter)=>{
 //do stuff
})

It just seems unnecessary to name a variable for the array you'll be iterating over. Also, why is the semicolon needed in order for the latter example to work?

j08691
  • 197,815
  • 30
  • 248
  • 265

0 Answers0