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

Bianca begins Part 2 of this course by reviewing a few of the concepts covered in Part 1 including the anatomy of a function.

Get Unlimited Access Now

Transcript from the "Scope Introduction" Lesson

>> [MUSIC]

>> Bianca Gandolfo: So this class is for someone who has for the first time, who's just started learning JavaScript for a few months, usually two to six months. Maybe you completed an online tutorial, like Code Academy, Code School Khan Academy, something like that. You want to continue solidifying your fundamentals.

[00:00:59] You're looking for more practice. Or you're trying to get into a Hack Reactor. So I initially create this class to help you prepare for the Hack Reactor interview. It's a two-part class. And this is the second part. The first part which I taught yesterday and will be also released on Front End Masters, just reviews the core foundations of JavaScript.

[00:01:21] We talked about objects, arrays, and functions. Those are some of the most important aspects of the language, as well as the most confusing for beginners. And then today we're gonna, we're gonna build on that, and we're gonna explore even more into functions. And you get started with some functional programming, with the underscore library.

[00:01:38] And the hope for this class is, once you have this strong foundation, you can go out and be an even stronger JavaScript engineer, cool. And so I'm just gonna jump right into review, cuz we have a lot to cover today and we only have seven hours, so here we go.

[00:01:58] So here's a chart from yesterday and we have the anatomy of a function. So what is the declaration or the definition of a function from yesterday?
>> Bianca Gandolfo: Joe.
>> Joe: The. It's the actual commands that get executed as part of the function.
>> Bianca Gandolfo: Yeah. So the function declaration just starts with the keyword function and it follows through to the brackets.

[00:02:35] So it contains the function. It contains the keyword function. The parameters and the function body. And what about the function name? You know that the function name here is being used loosely, to mean any way that we can refer to the function later in our code. So that could be the actual function name or it could be a variable where the function is stored.

[00:02:59] So, we have the function name. This is an add function, so we have yellow add here. That's the function name, and we refer to it down here as well. And then, we have the parameters. The parameters are placeholders or variables. They're like variables in that they don't have a value until they're assigned a value.

[00:03:18] The way that we assign parameters a value is by passing them arguments. And so here are arguments down here, we pass the arguments at call time. Or when we invoke the function. When we invoke the function is when we pass the arguments. And at that point, is when our parameters gain a value.

[00:03:35] Before that, our parameters are undefined. And then the other, the other important thing is the function body. The function body is never run until we call the function. So the functions body is in between these two parentheses here, and that code, that return A plus B is never, is never run until down here.

[00:04:00] So, if we were to pretend that we were in the interpreter, we'd start here, above this add function. We'd say, okay, great, we're going to create a variable and store this function on definition in that variable and memory. And then it's going to skip the entire function body, so that return a + b is never It's never run.

[00:04:21] And then once we get to the add functions, this variable add, yeah, it's a function, then we're gonna call it. And we're gonna pass these arguments here, three, four, and five. Then, at that point only does, it go into the function body, and run the containing code. So, we, We invoked it down here.

[00:04:44] And we skip back up. And then it goes into this statement, which is return A plus B. And also at that point is when we give value to our parameter. So at this point, is when A and B, now contain the values three and four. So, that was a review.

[00:05:05] Do we have any questions on sort of the anatomy of the function, the vocab words? So thumbs. So, and those of you joining online, thumbs, a thumb up is a B and a thumb down is a P, and then a middle thumb Is just a dash. And so we use our thumb to gauge where everyone's at in the room.

[00:05:28] And we're trying to be honest with each other about where we are, so that I can go slower or faster based on how the collective. And then, also, just gives me feedback on if I explained something thoroughly enough, or if I should explain something a different way. So it's really important to really be honest when we do our thumbs, cool.

[00:05:48] Lot's of thumbs up, down there, cool. So, so the slides, the slides link where it says. Forward/live. That is the live slideshow. So you can tune in there or you can just go through the slides yourself.