⊗jstsPmBsFn 14 of 55 menu

Functions in TypeScript

When declaring function parameters, we can also specify their type. See the example:

function func(a: number, b: number) { return a + b; }

You can also specify the return type of the function. Let's do that:

function func(a: number, b: number): number { return a + b; }

Specify the type of the function result and parameters:

function sum(x, y) { return x + y; }

Specify the type of the function result and parameters:

function sum(arr) { let res = 0; for (let num of arr) { res += num; } return res; }
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