Check out a free preview of the full JavaScript: From Fundamentals to Functional JS, v2 course:
The "Spread Operator" Lesson is part of the full, JavaScript: From Fundamentals to Functional JS, v2 course featured in this preview video. Here's what you'd learn in this lesson:

After a quick review, Bianca demonstrates the spread operator, which fills function arguments into an array.

Get Unlimited Access Now

Transcript from the "Spread Operator" Lesson

[00:00:00]
>> Bianca Gandolfo: So just a quick review here, what is this gonna return? Actually, let's play the game I was telling you guys before, where we're gonna run this code as a group. Who wants to go first?
>> Speaker 2: Create a constant called createTuple.
>> Bianca Gandolfo: Mm-hm, yeah, so we will Create constant variable, we'll name that variable createTuple.

[00:00:25] Does anyone know what a tuple is?
>> Bianca Gandolfo: A Tuple is a data structure that has an array, that has collection of arrays that have two values, call them a tuple. Okay, so we created this,
>> Bianca Gandolfo: Variable called tuple. What happens next?
>> Speaker 3: So that variable is set equal to a function.

[00:00:51]
>> Bianca Gandolfo: Yep, the variable is set equal to a function. Chris, what happens next?
>> Chris: The function is skipped until it is invoked.
>> Bianca Gandolfo: Yeah, extra points, so we skip down here. What happens next? Abdi?
>> Abdi: It takes the arguments from createTuple, and.
>> Bianca Gandolfo: Yeah, so we call the createTuple function with these arguments.

[00:01:17]
>> Abdi: Mm-hm.
>> Speaker 6: And then CreateTuple returns the first array with it could and the second array with be anyone.
>> Bianca Gandolfo: It could be anyone. It makes me so happy yeah, so it returns it could be anyone, awesome. So here's the spread operator. Have you guys seen this yet?

[00:01:47] I think this might be the first time that we really have started to talk about it. So, or the rest operator. What this done is, something to note is that we pass no one into this function and it wasn't picked up because we don't have a variable name that maps to that directly, right?

[00:02:12] So a is It, b be, c could, d anyone, right, you see that? There's no e to handle this so we have something handy called the Spread Operator and it takes care of that for us by doing something interesting. So it's gonna return, can you guys see this gray?

[00:02:34] So it's going to say It how interesting it's formatting my stuff, It and then could be and then we get another one in there and then it says anyone, no one, started with a weird formatting. Let me just put this
>> Bianca Gandolfo: There.
>> Bianca Gandolfo: So what it does is it gathers all the extra arguments at the end, and puts it in a handy little array.