December 2017
Beginner
372 pages
10h 32m
English
Rest parameters allow us to pass a variable number of parameters to a function and accept them as an array. A rest parameter is defined by prefixing the parameter name with ellipses (three dots). When the function is called, we can pass multiple parameters to that function, and the function will accept them in an array format. Check out the following example, where we define a function with rest parameters:
function School (name: string, ...id:number[]){}let harvard = new School("Harvard", 1,2,3,4,5);
Here, all the parameters passed to the second parameter are combined together and added to the number array.
Read now
Unlock full access