In this we can define that functions in Typescript .
Defining a Function :
A function definition specifies what and how a specific task would be done. Before using a function, it must be defined. Functions are defined using the function keyword.
Syntax :
function function_name() {
// function body
}
Calling a function :
To run a function, it must be invoked. Function invocation is the name given to this process.
Syntax :
Function_name()
Example:
function Crmonce() {
console.log(“function called”);
}
Crmonce(); // function invocation
Returning a function :
Functions may also return value along with control, back to the caller. Such functions are called as returning functions.
Syntax :
function function_name():return_type {
//statements
return value;
}
- The return_type can be any valid data type.
- A returning function must end with a return statement.
- A function can return at the most one value. In other words, there can be only one return statement per function.
- The data type of the value returned must match the return type of the function.
Parameterized Function :
Functions can be passed values through parameters. The signature of the function includes parameters. The function is called with the parameter values supplied to it. The number of values provided to a function must match the number of stated parameters, unless otherwise specified.
While calling a function, there are two ways that arguments can be passed to a function.
1.Call by value
2.Call by pointer
1.Call by value :
This method transfers an argument’s actual value into the function’s formal parameter. The argument in this situation is unaffected by modifications made to the parameter inside the function.
2.Call by pointer :
With this method, an argument’s address is copied into the formal parameter. The address is utilised within the function to obtain the actual argument used during the call. Thus, any modifications made to the parameter.
Anonymous Function :
Functions that are not bound to an identifier (function name) are called as anonymous functions. These functions are dynamically declared at runtime. Anonymous functions can accept inputs and return outputs, just as standard functions do. An anonymous function is usually not accessible after its initial creation.
Variables can be assigned an anonymous function. Such an expression is called a function expression.
Syntax :
var res = function( [arguments] ) { … }
For any Help or Queries Contact us on info@crmonce.com or +918096556344