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

  • 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; }; 
主站蜘蛛池模板: 阳高县| 特克斯县| 阳山县| 依安县| 新巴尔虎左旗| 黔江区| 忻城县| 泗洪县| 调兵山市| 和田县| 绥江县| 临武县| 南投市| 临颍县| 临汾市| 娄底市| 蒲城县| 治县。| 和田市| 忻州市| 县级市| 临泉县| 中江县| 长治市| 丽水市| 和平县| 昌黎县| 太康县| 会同县| 崇左市| 柳州市| 谢通门县| 施秉县| 视频| 明星| 金昌市| 阿拉尔市| 文安县| 嵊泗县| 萝北县| 嘉义县|