Global scope and Script scope
let a = 0; // script scope
var b = 0; // global scope
function c() {} // global scope
Global scope
var and function are contained by the window object. It means global scope.
That's why no need to write like below. Global object(window) can omit to write.
console.log(window.b);
window.c();
// We can omit "window"
console.log(b);
c()
Script scope
When we declare variables with let or const.
Those are gonna be script scope.
Generally, script scope is also called global scope, because script scope is similar to ease of use with global scope.
But to be exact it's different.
let a = 0;
const b = 0;
Top comments (0)