This course has been updated! We now recommend you take the JavaScript: From First Steps to Professional course.

Check out a free preview of the full JavaScript: From Fundamentals to Functional JS, v2 course:
The "Arguments Keyword" 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:

Bianca reviews arguments keyword, which is an object that references all the arguments from a function as a pseudo-array.

Get Unlimited Access Now

Transcript from the "Arguments Keyword" Lesson

>> Bianca Gandolfo: So before the spread operator, we had to rely on this arguments keyword to do stuff like that. And so here we are referencing the arguments keyword.
>> Bianca Gandolfo: How many people, you have used the arguments keyword in their code, okay. So arguments keyword references all the arguments as a pseudo array, yeah, a pseudo array, which is annoying.

[00:00:30] But a pseudo array is an object that looks like an array, but it's actually an object. What does that mean? That means that we don't have access to our handy array methods like push, pop, forEach, splice and stuff like that. And so that can be,
>> Bianca Gandolfo: It's great that we have it available but sometimes that can trip us up.

[00:00:52] And before when we would have to do some crazy array dot prototype to slice that call and you pass the array to turn it into a real array. Can you see how that's kind of annoying, and a lot of extra typing? We'll see the new ES6 feature that will save us all of that time.

[00:01:12] So with all of that said, what is this console.log gonna say?
>> Bianca Gandolfo: What is it gonna print out? So it looks like an array, but it's not really an array. We know that. But what's gonna be in here?
>> Speaker 2: So,
>> Speaker 2: At those five terms.
>> Bianca Gandolfo: Mm-hm
>> Speaker 2: It could be anyone but I'm wondering if no one is somehow set aside.

[00:01:49] Somehow because it wasn't, because it was passed in but it wasn't specified as a parameter.
>> Bianca Gandolfo: Well, actually you bring up a good point is that the reason that we use the arguments keyword is when we don't know how many arguments we're gonna get. That's when it's most useful because even if you pass in an extra argument and you don't reference it or give it a parameter name, you can use the arguments keyword to figure out how many extra arguments were passed, what they were, things like that.

>> Bianca Gandolfo: So what is this going to print out?
>> Speaker 3: It, be, could, anyone, no one? All of those arguments?
>> Bianca Gandolfo: That's a good guess. But remember we said that these error functions are kind of weird?
>> Speaker 3: Because they have no arguments, so would it return null or something?

[00:02:38] Or just print out nothing?
>> Bianca Gandolfo: Yeah, or it might throw an error, I don't know exactly what happens, but it's not gonna work as intended. So let's take a step back to our good old function keyword. And then we get what you thought was, it, be, could, anyone, no one, is what it would log.

[00:03:03] Cool, any questions about that? I see a couple faces that look confused.
>> Speaker 3: Maybe cuz the font [INAUDIBLE]
>> Bianca Gandolfo: Can you not read it, can you read it better in there?
>> Speaker 2: Not really. [INAUDIBLE]
>> Speaker 3: All right it's not default.
>> Bianca Gandolfo: Is that the error it gives you?

>> Speaker 3: Yeah.
>> Bianca Gandolfo: Yeah, okay, are we good? I saw some confused faces. I'm trusting you that you're gonna be honest and you're not gonna lie to me and that you understand. Unless you have a question, that's why I'm stalling, no? Okay.
>> Speaker 4: So hold on, what does spread operator, it now logs it?

[00:03:48] The arguments gets logged, or?
>> Bianca Gandolfo: The spread operator has nothing to do with what arguments prints out. Yeah. So the arguments keyword has everything to do with what is passed only. It only picks up what is being passed here. And the spread is doing something after the fact, if that makes sense.

[00:04:18] It's just taking it and putting it into a array. But the arguments keyword is only paying attention to what are the values that are being passed into this array. I'm sorry, into this function.