What is the difference between Uncaught ReferenceError and undefined?

Viewed 2001

In the following code, there are two instances of "undefined":

A:

b();
console.log(a);

var a = "Hello World!";

function b() {
 console.log("Called b!");    
}

This causes the console to show "Undefined" for "a".

B:

b();
console.log(a);

function b() {
 console.log("Called b!");    
}

This creates "Uncaught ReferenceError: a is not defined". In both cases a is undefined, and the console tells you that. But why does it choose to do it in different ways depending on the context? Are there a couple forms of "undefined" besides undefined and null?

2 Answers
Related