Functions and Classes#
Functions#
Function Declaration#
function sum(x: number, y: number): number {
return x + y;
};
console.log(`Declaration: ${sum(10, 10)}`);
Function Expression#
let sum2 = function (x: number, y: number): number {
return x + y;
};
console.log(`Expression: ${sum(20, 20)}`);
Arrow Function#
Used for anonymous functions
(param1,..., paramN) => expression
Used =>
, passed parameters in ()
, and expression enclosed within {}
without parameters: