⊗jstsPmFnDPV 50 of 55 menu

Default Parameter Values ​​in TypeScript

Optional parameters can also be assigned a default value. In this case, the question mark to indicate that the parameter is optional is not written. As an example, let's assign the value 'snow' to those users who do not have a last name:

function func(first: string, last: string = 'snow') { return first + ' ' + last; }

Let's now use our function. Let's call it with two parameters:

func('john', 'smit'); // will return 'john smit'

Let's call it with one parameter:

func('john'); // will return 'john snow'

Create a function that will raise a number to a given power. Let the function take a number as its first parameter, and the power as its second. Let the second parameter be optional, and let the function raise the number to the second power by default.

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