- Global scope
- Local scope
Global scope
var a = 1;
console.log(a); //1
console.log(window.a); //1Local scope(function scope)
- variable
foodoesn't exist in a global scope. foo exists and be avaiable only inside local scope.
"use strict";
function moo(){
var foo = 1;
}
console.log(foo);//foo is not defined - JavaScript doesn't have the concept of block level scope.
for(var i=0; i< 3; i++){
var j = 5;
}
console.log(j); //5