// rest parameters = (...rest) allow a function work with a variable // number of arguments by bundling them into an array // spread = expands an array into separate elements // rest = bundles separate elements into an array // -------- EXAMPLE 1 -------- function openFridge(...foods){ console.log(...foods); } function getFood(...foods){ return foods; } const food1 = "pizza"; const food2 = "hamburger"; const food3 = "hotdog"; const food4 = "sushi"; const food5 = "ramen"; openFridge(food1, food2, food3, food4, food5); const foods = getFood(food1, food2, food3, food4, food5); // -------- EXAMPLE 2 -------- function sum(...numbers){ let result = 0; for(let number of numbers){ result += number; } return result; } function getAverage(...numbers){ let result = 0; for(let number of numbers){ result += number; } return result / numbers.length; } const average = getAverage(75, 100, 85, 90, 50); console.log(average); // -------- EXAMPLE 3 -------- function combineStrings(...strings){ return strings.join(" "); } const fullName = combineStrings("Mr.", "Spongebob", "Squarepants", "III"); console.log(fullName);
heyy..!!! Bro Code..!! Thanks for this amazing PHP course...!!! But Now we want Laravel Complete course Zero to Hero..!! so please as soon as possible made a full video course on PHP laravel..!!
// rest parameters = (...rest) allow a function work with a variable
// number of arguments by bundling them into an array
// spread = expands an array into separate elements
// rest = bundles separate elements into an array
// -------- EXAMPLE 1 --------
function openFridge(...foods){
console.log(...foods);
}
function getFood(...foods){
return foods;
}
const food1 = "pizza";
const food2 = "hamburger";
const food3 = "hotdog";
const food4 = "sushi";
const food5 = "ramen";
openFridge(food1, food2, food3, food4, food5);
const foods = getFood(food1, food2, food3, food4, food5);
// -------- EXAMPLE 2 --------
function sum(...numbers){
let result = 0;
for(let number of numbers){
result += number;
}
return result;
}
function getAverage(...numbers){
let result = 0;
for(let number of numbers){
result += number;
}
return result / numbers.length;
}
const average = getAverage(75, 100, 85, 90, 50);
console.log(average);
// -------- EXAMPLE 3 --------
function combineStrings(...strings){
return strings.join(" ");
}
const fullName = combineStrings("Mr.", "Spongebob", "Squarepants", "III");
console.log(fullName);
You should have more views
Perfect explanation! Thank you!
If you are reading this and you know BroCode in person give him flowers He deserves it million times . Thank you bro.
Thank you for providing us this high-quality content
Thank you for providing a high-quality edition for free! Love your content. Will you create Assembly series?
This man is a gem ❤❤
This is crazy! Very well explained. Thank you!
Congrats on 2 mil subs Bro!!
Thank you bro for providing this type of content, even if you don't have enough views, best of the best
Wow, thank you so much, you explain super clear!
This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal.
Thank you very much😃
You are the best😀
you are great! Hi by Brazil
One day, I hope I can meet him in person and express my gratitude for helping me through the journey to become a web and software developer.
Hello bro!Nice video!
combineString("Mr", "Bro", "Code");
function combineString(...str){
console.log(...str);
can we do like this also?
Django course pls
Hey Bro could you please upload react videos often please
When NodeJS?
heyy..!!! Bro Code..!! Thanks for this amazing PHP course...!!! But Now we want Laravel Complete course Zero to Hero..!! so please as soon as possible made a full video course on PHP laravel..!!
Explain nodeJS to us
Thank you so much