// 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.
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.
Thank you for providing a high-quality edition for free! Love your content. Will you create Assembly series?
Congrats on 2 mil subs Bro!!
Explain nodeJS to us
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.
combineString("Mr", "Bro", "Code");
function combineString(...str){
console.log(...str);
can we do like this also?
Wow, thank you so much, you explain super clear!
Thank you bro for providing this type of content, even if you don't have enough views, best of the best
Thank you for providing us this high-quality content
This is crazy! Very well explained. Thank you!
When NodeJS?
Hey Bro could you please upload react videos often please
you are great! Hi by Brazil
Thank you very much😃
Django course pls
Hello bro!Nice video!
You are the best😀
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..!!
Thank you so much