Easy learning with example program codes

typescript function overloading tutorial

A TypeScript function is a group of statements which is used for performing a specific task. It provides the facility of code re-usability.

Method overloading means more than one methods with the same name but different parameters. Parameters can be differing in types, numbers or order.

Ways to implement method overloading:

  • Parameters differ in types.
    function showDetails(s1:string):void; 
    function showDetails(num1:number):void;
  • Parameters differ in number.
    function showDetails(s1:string):void; 
    function showDetails(x:string, y:string):void;
  • Parameters differ in order
    function showDetails(num1:numer, s1:string):void; 
    function showDetails(s2:string, num2:number):void;

Typescript function overloading example:

function showDetails(name:string):void{
function showDetails(empId:number):void{

Try it:

JS Bin on

Please follow and like us:

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki