CodesJava

Easy learning with example program codes

typescript function overloading tutorial

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{
  console.log(name); 
} 
function showDetails(empId:number):void{
  console.log(empId); 
}
showDetails("Jai") 
showDetails(123);

 

Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status