Typescript – declaring function

Hi, in this post we are going to see 5 ways that we can use to declare function types and the function paramaters.

In this code we can see a function that we can set 2 parameters but this 2 parameters need to be a number and also the function will return a number.

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

Here the code were we can different ways to declare functions.

function greet(name: string) {
    return 'hello ' + name;
};

let greetTwo = function(name: string) {
    return 'hello' + name
}

let greetThree = (name: string) => 'hello' + name

let greetFour = new Function('name', 'return "hello" + name')

By Cristina Rojas.