官术网_书友最值得收藏!

  • Expert Angular
  • Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
  • 135字
  • 2021-07-15 17:05:33

Functions

JavaScript, which follows the ES5 specs, does not support classes and modules. However, we tried to scope variables and modularity using functional programming in JavaScript. Functions are the building blocks of an application in JavaScript.

Though TypeScript supports classes and modules, functions play a key role in defining a specific logic. We can define both named functions and anonymous functions in JavaScript as follows:

//Named function 
function multiply(a, b) { 
    return a * b; 
} 
 
//Anonymous function 
var result = function(a, b) { return a * b; }; 

In TypeScript, we define functions with the type of the parameters and the return type using function arrow notation, which is also supported in ES6, as follows:

var multiply:(a: number, b: number) => number = 
          function(a: number, b: number): number { return a * b; }; 
主站蜘蛛池模板: 固阳县| 华阴市| 黄浦区| 北安市| 渝北区| 乐亭县| 嘉定区| 延庆县| 涞水县| 横峰县| 庐江县| 文成县| 通河县| 阜南县| 界首市| 连南| 麻江县| 楚雄市| 都江堰市| 项城市| 公主岭市| 寿阳县| 商水县| 汉沽区| 恩平市| 偏关县| 陇西县| 汉川市| 门头沟区| 东明县| 岚皋县| 通城县| 栾川县| 城口县| 偏关县| 新建县| 嘉峪关市| 昭苏县| 林口县| 临安市| 临沂市|