I don't understand what the scope is. I've read somewhere that scope is the way to access varible. But I find it hard to come up with a case when a variable is accesible through scope. All varibles inside a function can be accessed through context of either 'global' or 'activation/variable' object or through closure. Here is the piece of code to demonstrate what I mean:
var global_var = 7;
var f = (function() {
var closure_var = 5;
return function() {
var local_var = 3;
alert(local_var); // alerts 3 - visible through context as Activation Object's property
alert(closure_var); // alerts 5 - visible through closure
alert(global_var); // alerts 7 - visible through context as Global Object's property
alert(this.global_var); // alerts 7 - visible through context as Global Object's property
}
})();
f();
So what is scope? Here is the extract from here and my comments:
// a globally-scoped variable
var a=1;
// global scope
function one(){
alert(a);
}
// no, it's accessible as global object's context
// local scope
function two(a){
alert(a);
}
// no, it's accessible as activation object's context
EDIT:
Thanks to everyone. I guess I'll have to look at scope from the point of variable and function.