typescript / beginner
Snippet
Function Parameter and Return Types
You can define the expected types for function arguments and specify what type of data the function will return.
snippet.ts
1
2
3
function calculateTotal(price: number, tax: number): number {return price + tax;}
Breakdown
1
function calculateTotal(price: number, tax: number)
Specifies that both 'price' and 'tax' must be numbers.
2
): number {
Indicates that the function is required to return a number.