-6

Semicolon is optional in JavaScript. However, could I omit the semicolons in the for loop? For example:

for (let i = 0 i < arr.length i++) {
    console.log(arr[i])
}

I'm new to JavaScript, I'm coming from C and C++ where semicolon is a must.

  • 4
    No. Trying it out would have quickly answered this – Phil Aug 02 '22 at 06:34
  • 5
    Semicolons *as statement terminators before a line break* are optional in *most* situations (not all). The `;` inside a `for` isn't a statement terminator. It's part of the syntax of the `for`, and a line break there won't do its job for it. – T.J. Crowder Aug 02 '22 at 06:41

1 Answers1

-1

Semicolons are used when you have more than one statements. If you have only one statement in for loop , you don't need to put semicolon.