The spread operator (…) spreads out the elements of an array (or iterable object). The rest operator condenses elements. The spread and rest operators are great additions to ES6!
đ Code: http://codepen.io/beaucarnes/pen/EWabjW?editors=0012
đ More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator
Beau Carnes on Twitter: https://twitter.com/carnesbeau
âJavaScript Playlistsâ
â¶JavaScript Basics: https://www.youtube.com/playlist?list=PLWKjhJtqVAbk2qRZtWSzCIN38JC_NdhW5
â¶Data Structures and Algorithms: https://www.youtube.com/playlist?list=PLWKjhJtqVAbkso-IbgiiP48n-O-JQA9PJ
â¶Design Patterns: https://www.youtube.com/playlist?list=PLWKjhJtqVAbnZtkAI3BqcYxKnfWn_C704
â¶ES6: https://www.youtube.com/playlist?list=PLWKjhJtqVAbljtmmeS0c-CEl2LdE-eR_F
â¶Clean Code: https://www.youtube.com/playlist?list=PLWKjhJtqVAbkK24EaPurzMq0-kw5U9pJh
–
We’re busy people who learn to code, then practice by building projects for nonprofits. Learn Full-stack JavaScript, build a portfolio, and get great references with our open source community.
Join our community at https://freecodecamp.com
Read great tech articles at https://medium.freecodecamp.com
source
Don't forget to subscribe and remember, USE YOUR CODE FOR GOOD!
Thanks for the great explanation.
You are too good.
Am i the only one who hard to grasp ES6 ? like my brain cells is not functioning lol.
am confused at the last when i mutiply the parameters like this it outputs 'null', does anyone know why? for i.e:
function multiply(multiplier, …theArgs) {
return multiplier * theArgs;
}
var arr = multiply(2, 1, 2, 3);
console.log(arr)
Excellent, ty
thanks
clear as crystal, thanks
Thank you. Very useful explanation. Great job Beau!
They should add this video to FreeCodeCamp because they have watered down the explanation on "Use the Rest Parameter with Function Parameters".
Thanks
I just found the series "Beau teaches JavaScript," and boy, this is the best JavaScript tutorial series (at least about the topics covered). He is straight to the point, has a clear and clean voice that is easy to understand, and uses a good speech pace. Well, anyway, You got a new sub with notifications on đ
u are a great teacher
what would …foo[bar] evaluate to ?
I don't understand the statment at 5:18 where you explain how you know the difference between the spred opperator and the rest opperator. They look the same to me and seem to be used the same. Perhaps I do not undersatnd what is means to be "passed into an argument as a function." Could someone elaborate?
Thanks for the clear and precise explanation of the 3 dots !
2:28
is there a benefit to using the spread operator when assigning arr2 to the value of arr? I tried coding it as let arr2 = arr; and it worked just fine. And the push method worked the same as well. I also tried concatenating by coding let arr1 = arr1 + ',' + arr2; which worked fined and that seems like less to type out. Is there a benefit to using the spread operator here as well?
Thanks Beau! This I understand.
Thank you for this video!!!
Omg.This is awesome!
I am on my 3rd year of IT degree . I got to know this today
so easily explained, thank you
Thanks Beau. I was stuck on the FCC lesson about REST parameters and this really explained it well.
To convert string to array
let str = "Hello";
let x = […str];
thank you.!
Concise and to the poin! Thanks a ton
Excellent video
Neat
the best tutorials
Straight forward and useful explanation. Pretty helpful.
great explanation thank you! although the last one about the rest operator is still confusing
in this section we talked about spread out arrays. here's another helpful link for spread object. https://www.youtube.com/watch?v=MpnzQozwLGI
I remember being here, watching this video, doing some exercises. But here I am again, not having a slight idea what spread and rest operators are. fml
thanks )) you are one of the best teaacher in js in the world
hmmm.. i almost get it don't understand line 33 this is the first time i saw two return statement in a function..???
Beau… you a G my man. Thank you
Wow! You did a great job here in your explanations. I can't just pass without saying "God will continue to bless you with more knowledge".