⊗jsPmCdBO 125 of 504 menu

Optionality of curly braces in JavaScript

If there is only one expression in curly brackets in if or else, these curly brackets can be omitted. Let, for example, given the following code with all brackets:

if (test === 0) { console.log('+++'); } else { console.log('---'); }

You can shorten it like this:

if (test === 0) console.log('+++'); else console.log('---');

Or so:

if (test === 0) { console.log('+++'); } else console.log('---');

You can also remove all the brackets, but arrange everything not in one line, but like this:

if (test === 0) console.log('+++'); else console.log('--');

Rewrite the following code in shortened form:

if (test > 0) { console.log('+++'); } else { console.log('---'); }

Rewrite the following code in shortened form:

if (test > 0) { console.log('+++'); }
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