Skip to content

Files

Latest commit

 

History

History

nested_scopes

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Nested Scopes

Take a look at the following code but don't execute it in the console.

{var a = 1;{var b = 2;{( function() {var c = a + b;} )()}}c;}

What's the result of executing the previous code?

ReferenceError: c is not defined
__match_answer_and_solution__


Why?

The cause of the error is because Javascript only has not block scopes as in other languages, then 'c' only exist inside the function block and it throws an error when we are trying to call it from the current scope.
__match_answer_and_solution__