/typescript/

TypeScript part 15 (arrow functions)

2017-03-04 15:21:03

TypeScript

const add1 = function (num1: number, num2: number): number {
    return num1 + num2;
};

const add2 = (num1: number, num2: number): number => num1 + num2;

console.log(add1(3,7));
console.log(add2(3,7));

JavaScript

var add1 = function (num1, num2) {
    return num1 + num2;
};
var add2 = function (num1, num2) { 
    return num1 + num2; 
};
console.log(add1(3, 7));
console.log(add2(3, 7));

TypeScript

const add3 = function(num: number):number{
    return num + 10;
}

const add4 = num => num + 10;

JavaScript

var add3 = function (num) {
    return num + 10;
};
var add4 = function (num) { 
    return num + 10; 
};

TypeScript

const log1 = function () {
    console.log("Log 1");
};

const log2 = () => {
    console.log("Log 2");
};

JavaScript

var log1 = function () {
    console.log("Log 1");
};
var log2 = function () {
    console.log("Log 2");
};