Rest parameters

Using the rest parameter, you can pass an array of values to the function. This can be used in scenarios where you are unsure about how many values will be supplied to the function:

function clientName(firstClient: string, ...restOfClient: string[]) { 
console.log(firstClient + " " + restOfClient.join(" "));
}
clientName ("Scott", "Steve", "Bill", "Sergey", "Larry");

Here, note that the restOfClient rest parameter is prefixed with an ellipsis (...), and it can hold an array of strings. In the caller of the function, only the value of the first parameter that is supplied will be assigned to the firstClient parameter, and the remaining values will be assigned to restOfClient as array values.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset