Function

  • Similar to JavaScript functions

  • Have some additional features...

    • types

    • default parameters

    • rest parameters

    • lambdas

function greet(){
    alert("Hello world.");
}

Function Types

  • Functions can have types

  • Types describe what is returned by a function

function getCountry() : string {
    return "Canada";
}
var c : string = getCountry(); // ok
var c : number = getCountry(); // compile-time error

Optional Parameters

Default Parameters

Rest Parameters

  • In JavaScript list of all arguments are provided in the mysterious arguments variable

  • it's real array ( so we can use array methods push, pop etc on it unlike arguments )

Lambdas ( arrow function )

  • A different kind of function invocation where the value of this is not changed

  • Works similar to function but has a preferable syntax

  • Also known as an arrow or a fat arrow function

Last updated

Was this helpful?