Step 60 semicolon inside a for

Hi! I have doubt here. In This and the previous step, I can see that a semicolon hasn’t been used at the end of .push() line.

for (let i = 0; i < count; i = i + 1) {
  rows.push(padRow())
}

I thought there had to be a semicolon at the end of that line. Even I put a semicolon at the end of that line and the code run perfectly, so what is the difference?

It will work either way because JavaScript has a feature called
“Automatic Semicolon Insertion” ( ASI )

It automatically inserts semicolons at the end of the lines if you omit them.

However, it’s considered best practice to use semicolons explicitly to improve code clarity and avoid some pitfalls associated with ASI.

1 Like

Excellent! Thank you very much!

Note, sometimes it doesn’t work as expected and you get unexpected bugs. Adding semicolons work better