Check out a free preview of the full Advanced JavaScript course:
The "zz: Scope" Lesson is part of the full, Advanced JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Kyle presents a quiz about what was covered in the Scope section of this course and reviews the answers with the audience.

Get Unlimited Access Now

Transcript from the "zz: Scope" Lesson

[00:00:00]
>> [MUSIC]

[00:00:04]
>> Kyle Simpson: Let's review where we've been so far. What types of scoping rule or rules does JavaScript have? What's the scope rule called?
>> Speaker 2: Lexical
>> Kyle Simpson: Lexical scoping, that's the one. What are the exceptions, how do we cheat lexical scopin
>> Speaker 2: Eval.
>> Kyle Simpson: Eval and the width key rule, those are two ways to cheat with the exceptions to lexical.

[00:00:27] What are the different ways you can create a new scope?
>> Speaker 2: Functions.
>> Kyle Simpson: Functions create a new scope, what else?
>> Speaker 2: A catch.
>> Kyle Simpson: Catch blocks create a new scope, what else?
>> Speaker 3: Curly braces.
>> Kyle Simpson: The curly braces with the let keyword will create a new scope, okay?

[00:00:45] What's the difference between undeclared and undefined? Remember I mentioned that earlier? Can anybody remember? What's the difference between undeclared and undefined?
>> Speaker 2: Undefined has a value.
>> Kyle Simpson: Undefined is a value.
>> Speaker 2: Is a value.
>> Kyle Simpson: What is undeclared?
>> Speaker 2: It hasn't been registered to any scope yet.
>> Kyle Simpson: It's never been declared.

[00:01:03] So another way of explaining undefined. Some people say undefined means it's a variable that doesn't yet have a value. That's not really correct cuz a variable can have a value and then not have a value. So really the proper way of thinking about it if you want to sort of, conceptually is undefined means doesn't currently have a value.

[00:01:20] Or currently, the value is sort of an empty placeholder or something like that. It's another way of thinking about it. But, it means explicitly, if you have an undefined value, there there definitely was a declared variable. Cuz if there's not a declared variable, what you're gonna get back is a reference error.

[00:01:38] That make sense? So keep declared and defined, even though they sound like synonyms, keep them separate.