⊗jsPmLpBO 154 of 504 menu

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); }
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline