Function With Parameter in TypeScript

Function with Parameter in TypeScript

A Function is a block of code that you can use multiple times in an application. It can require one or more parameters. A list of parameters in parentheses, and a block of code in braces. To call a function, you code the function name followed by the function's parameters or arguments in parentheses. The following uses parameters as it executes its block of code. Some rules of functions with parameters:

  • A function must start with "{" and end with "}"
  • For calling a function simply use the function name ( Myfunction() )
  • When calling a function, the function signature must be the same.
  • In a function with a parameter, pass the parameter(s) inside parantheses.
  • You can pass as many parameters as you like. These parameters work like variables inside your function.
  • A parameter appears within parentheses "( )"


The following example shows a simple function (triangle) with a parameter but no return type. In this example I have a Parameter_function class and define the triangle function. In the class we enter the number of rows in the triangle of a star. Let's use the following procedure.

Step 1

Open Visual Studio 2012 and click "File" -> "New" -> "Project...". A window is shown. Give the name of your application as "Prameter_function" and then click ok.


Step 2

After this session the project has been created. A new window is opened on the right side. This window is called the Solution Explorer. The Solution Explorer contains the ts file, js file, css file, webconfig file and html file:




class Parameter_function




        var row: number, c: number;

        for (row = 1; row <= a; row++)


           for (c = 1; c <=row;c++)       






window.onload = () =>


    var greeter = new Parameter_function();

    var a: number;

    a = parseInt(prompt("Enter the number of rows in triangle of stars you wish to see"));











    <title>Function With parameter Without Return Type</title>





    <h3>Function With parameter Without Return Type Example In TypeScript</h3>






var Parameter_function = (function () {

    function Parameter_function() { }

    Parameter_function.prototype.triangle= function (a) {

        var row;

        var c;


        for(row = 1; row <= a; row++) {

            for(c = 1; c <= row; c++) {






    return Parameter_function;


window.onload = function () {

    var greeter = new Parameter_function();

    var a;

    a = parseInt(prompt("Enter the number of rows in triangleof stars you wish to see"));




Output 1


Enter the number of rows then click on the ok button.


Output 2



Reference By