Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Object JavaScript - Scope
var globalvar = 1; // Global Scope
function outer() {
var outervar = 2; // Scope is within outer()
function inner() {
var innervar = 3; // Scope is within inner()
console.log(globalvar); // => 1
console.log(outervar); // => 2
console.log(innervar); // => 3
}
console.log(globalvar); // => 1
console.log(outervar); // => 2
console.log(innervar); // => Reference Error;
}
console.log(globalvar); // => 1
console.log(outervar); // => Reference Error
console.log(innervar); // => Reference Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment