Следите за новинками
в нашем Telegram канале. Жми, чтобы подписаться:)
⊗jsPmDstAFDV 303 of 504 menu
◀ ▶

Default functions when destructuring an array in JavaScript

You can also specify a function as the default value. Let, for example, we have a function that returns the current day of the month:

function func() { return (new Date).getDate(); }

Let's specify this function as the value of the variable day:

let [year, month, day = func()] = arr;

Modify the code obtained above so that if there is no value for the month in the array, the current month is taken by default, and if there is no value for the year, the current year is taken accordingly.

← →
↑
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