Check out a free preview of the full Deep JavaScript Foundations, v3 course:
The "Undefined vs Undeclared" Lesson is part of the full, Deep JavaScript Foundations, v3 course featured in this preview video. Here's what you'd learn in this lesson:

Kyle reviews the difference between a variable that is undefined versus one that is undeclared.

Get Unlimited Access Now

Transcript from the "Undefined vs Undeclared" Lesson

[00:00:00]
>> Kyle Simpson: Let's make sure we're fully clear on this whole undefined versus undeclared thing. Might be review for some of you but let's just make sure we're fully clear. What is the difference between undefined and undeclared? Anyone?
>> Speaker 2: You're declaring this variable exist, I'm not assigning it a value but it exist.

[00:00:17]
>> Kyle Simpson: Okay, that's true.
>> Speaker 2: So there it's declared but not defined.
>> Kyle Simpson: Okay.
>> Speaker 3: Undeclared.
>> Kyle Simpson: All right, that's part of it, you're on the right track but that's not all of it yet.
>> Speaker 3: Undeclared has have never had the memory allocated during the compiler parsing stage whereas undefined.

[00:00:40] Maybe it was allocated but there's never been a value assigned to that.
>> Kyle Simpson: Putting both of your answers together we can get the complete answer. So let me restate that. You are both correct. You're on the right track so let me restate this. The difference between these two, undefined means a variable exists but at the moment it has no value.

[00:00:59] It may have never had a value or it might have used to have a value and it doesn't anymore but there is no other value in the vacuum of space it is undefined, right? Undeclared even though they sound like synonyms undeclared is actually never formally declared in any scope that we have accessed to.

[00:01:18] That's what undeclared means. We do not have a marble for it. And in strict mode, it always results in those reference areas, okay? It's important to keep those straight. Unfortunately, JavaScript tries to mess around with this and pretend that undeclared is sort of the same thing as undefined and some of its error messages and other outputtings and things and not is historically a really bad idea.

[00:01:43] We need to keep these two concepts separate. There's a different something being undeclared doesn't exist, and being undefine definitely it does exist, but doesn't have a value.