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

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; }; 
主站蜘蛛池模板: 古蔺县| 元朗区| 敦化市| 丹东市| 湛江市| 和顺县| 诸暨市| 汤阴县| 沅陵县| 松潘县| 沙坪坝区| 思茅市| 喀喇沁旗| 北安市| 疏附县| 新绛县| 富平县| 蒙自县| 孟州市| 珲春市| 灵寿县| 万州区| 金坛市| 西盟| 汕尾市| 兴和县| 平昌县| 大宁县| 民县| 阳新县| 柏乡县| 田林县| 志丹县| 玉田县| 金寨县| 申扎县| 方山县| 新余市| 宜宾县| 平定县| 龙泉市|