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:
javascriptfor (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:
javascriptfor (let i = 0; i <= 9; i++)
console.log(i); // will output numbers from 0 to 9
Задание 1
Rewrite the following code without the curly braces:
javascriptlet arr = [1, 2, 3, 4, 5];
for (let elem of arr) {
console.log(elem);
}