Easy learning with example program codes

typescript rest parameters 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.

When we talked about optional and default parameters all have one common thing, they talk about one parameter at a time. Sometimes we need multiple parameters as a group. TypeScript rest parameters used in such situations. They are act as the placeholder for multiple arguments of the same type. Use the ellipsis (…) as the prefix of rest parameter.

Typescript rest parameters syntax:

function function_name (…param1:datatype)

Typescript rest parameters example:

function showNames(...names:string[]) {    
   for(var i = 0;i<names.length;i++) { 
showNames("Mahesh", "Jai", "Narender", "Vishal", "Hemant");

Try it:

JS Bin on

Please follow and like us:

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki