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 "Closure" 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 examples of closure which occurs when one function returns another function, and the returning function retains access the scope.

Get Unlimited Access Now

Transcript from the "Closure" Lesson

[00:00:00]
>> All right, so we're gonna talk about advanced scope. So this is our second time talking about scope. You guys ready for this? This is gonna require us to do the thing where we run it together. So we have to be ready. So we gotta stretch we're gonna do some advanced scope here.

[00:00:25] Okay, so we have a function called alert. Let's just call it here. All right, who wants to go first?
>> Constant of x is set to that string inside the function.
>> Yeah, well, first, we have to set it up, then we'd call it.
>> I thought we skipped that part.

[00:00:49]
>> Yeah, you're right. We didn't skip that part. But yeah, you're right. Then we do this, right? We save the string into the x constant, and then what happens?
>> Then we set another constant alerter, which describes another function.
>> Yeah, typo, Okay.
>> Then we run alerter and As in constant x into the alert method.

[00:01:22]
>> Do you know what alert does?
>> Pops up on your window?
>> Yeah, it does but only if you aren't masking it. [INAUDIBLE] see how has this bug anyway, I give up. You want to rename this? This is gonna give us an error. So alert, this is gonna call itself and it's gonna just go over cursing forever.

[00:01:51] So make sure that it's myAlert. Cool, so, we have an alert that pops up and it says, help, I think I found a clue.