TypeScript Anonymous Functions - Syntax & Examples - Tutorial Kart
TypeScript Anonymous Functions ¨C Syntax & Examples
TypeScript Anonymous Functions
TypeScript Anonymous Functions are functions that are not bound to an identifier i.e., anonymous functions do
not have name of the function.
Anonymous functions are used as inline functions. These are used when the function is used only once and
does not require a name. The best example is a callback function.
Syntax of Anonymous Function in TypeScript
var varName = function( [arguments] ) {
// function body
}
var is the keyword
varName is the name of the variable in which function is stored
function (is a keyword) is an operator that creates a TypeScript Function during runtime
arguments are optional variables that could be declared for the anonymous function
function body can contain multiple lines of code
Example 1 ¨C Anonymous function with arguments
In the following example, an anonymous function is defined and assigned to a variable named result.
example.ts
var result = function(a:number, b:number) {
return a+b
}
var c = result(12,2) // c = 14
When the above code is transpiled, following JavaScript code is generated.
example.js
var result = function (a, b) {
return a + b;
};
var c = result(12, 2); // c = 14
Example 2 ¨C Anonymous function with no arguments
example.ts
var displayMessage = function () {
console.log("Hello User!")
}
displayMessage()
Transpiled JavaScript code would be as shown below.
example.js
var displayMessage = function () {
console.log("Hello User!");
};
displayMessage();
Output
Hello User!
Conclusion
In this TypeScript Tutorial ¨C TypeScript Anonymous Functions, we have learnt how to define an anonymous
function with and without parameters using the help of detailed examples.
TypeScript
?
TypeScript Tutorial
?
TypeScript Variables
?
TypeScript if
?
TypeScript if-else
?
TypeScript Switch
?
TypeScript For Loop
?
TypeScript While Loop
?
TypeScript Do-While Loop
?
TypeScript Arrays
?
TypeScript Tuples
?
TypeScript Unions
?
TypeScript Functions
?
TypeScript Anonymous Functions
TypeScript Object Oriented Concepts
?
TypeScript Class
?
TypeScript Inheritance
?
TypeScript Method Overriding
?
TypeScript Interface
TypeScript String Operations
?
TypeScript String Length
?
TypeScript String Split
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- how to dns enumeration
- declare enum in typescript hers index
- ecmascript language specification
- json rpc microchip technology
- advanced chisel topics university of california berkeley
- compressed double array tries for string dictionaries supporting fast
- typescript method overriding tutorial kart
- ecmascript a general purpose cross platform programming language
- typescript anonymous functions syntax examples tutorial kart
- typescript string length example tutorial kart
Related searches
- narcotics anonymous why are we here
- anonymous term life insurance quotes
- logarithmic functions examples and answers
- why are we here narcotics anonymous pdf
- free anonymous email no registration
- piecewise functions examples pdf
- anonymous voice changer pc
- free narcotics anonymous literature
- narcotics anonymous step working guides pdf
- step 2 narcotics anonymous pdf
- narcotics anonymous free downloads
- free narcotics anonymous literature download