⊗jsPmDstOVDV 308 of 504 menu

Variables and default values in JavaScript

You can also change the variable names to your own while setting the default values:

let obj = { month: 12, day: 31, }; let {year:y = 2025, month, day} = obj; console.log(y); // shows 2025 console.log(month); // shows 1 console.log(day); // shows 31

In the following code, parts of the object are written to the corresponding variables:

let options = { width: 400, height: 500, }; let c; if (options.c !== undefined) { c = options.color; } else { c = 'black'; } let w = options.width; let h = options.height;

Rework this code through destructuring according to the learned theory.

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