CodesJava

Easy learning with example program codes

typescript default function parameters


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

The TypeScript default-initialized parameters are used to set a default value to the parameter if the user does not provide one.
Note: We cannot declare a parameter optional and default at the same time.

Typescript default parameters syntax:

function function_name(param1:datatype,param2:datatype = default_value)

Typescript default parameters example:

function displayDetails(name:string,sport:string = "Cricket") {  
   console.log("Name: " +name + ", Sport: "+ sport); 
} 
displayDetails("Jai");
displayDetails("Vivek","Football");

Try it:

JS Bin on jsbin.com
 

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki