Optional Parentheses in JavaScript Loops
Curly braces are optional in loops. If you omit them, the loop will only execute the one line below it.
Let's look at an example. Let's say we have some loop with curly brackets:
for (let i = 0; i <= 9; i++) {
console.log(i); // will output numbers from 0 to 9
}
Let's omit the curly braces - and the result will not change:
for (let i = 0; i <= 9; i++)
console.log(i); // will output numbers from 0 to 9
Rewrite the following code without the curly braces:
let arr = [1, 2, 3, 4, 5];
for (let elem of arr) {
console.log(elem);
}