What is Rest parameter in Javascript.
Rest parameter is a modern feature of Javascript that allows a function to store multiple arguments in a single array.
It is similar to param keyword in C#.
Lets understand it by an example.
function sendOrders(...allOrderIds)
{
allOrderIds.forEach(id=>console.log(id));
}
sendOrders(100,200,300);
//output
//100 200 300
...allOrderIds is a rest parameter. In sendOrders function we are passing three integer and all will be stored in allOrderIds array.
We can send any number of parameter in Rest parameter.
Rest parameter with normal parameter:
function sendOrders(day,...allOrderIds)
{
allOrderIds.forEach(id=>console.log(id));
}
sendOrders('Monday',100,200,300);
Rest parameter should be the last parameter in a function:
function sendOrders(...allOrderIds,day) //Error
{
allOrderIds.forEach(id=>console.log(id));
}
Above code will throw an error saying "comma is not permitted after the rest element", because rest parameter should be last parameter.
In Madden 22, if players want to get these powerful cards, they’d better buy Madden 22 Coins at GameMS.
ReplyDeleteAttached link: https://www.gamems.com/madden-22-coins
steroid satın al
ReplyDeleteheets
FA0QD
kuşadası
ReplyDeletemersin
ordu
bolu
maltepe
HJAEXQ