/typescript/

TypeScript part 16 (default value)

2017-03-04 15:55:28

TypeScript

const add = (num1: number, num2: number = 10): number => {
    return num1 + num2;
};

console.log(add(1));
console.log(add(1, 10));
console.log(add(1, 20));

JavaScript

var add = function (num1, num2) {
    if (num2 === void 0) { num2 = 10; }
    return num1 + num2;
};
console.log(add(1));
console.log(add(1, 10));
console.log(add(1, 20));