<script>
let GLOBAL_DATA = {value : 1};
</script>
Pretend in the console, that we type:
console.log(GLOBAL_DATA);
let x = 1; // global
{
let x = 2; //local
}
console.log(x); //1
var x = 1; // global
{
var x = 2; // global
}
console.log(x); //2
function outerFn() {
let x = 1;
function log() {
console.log(x);
};
function run(fn) {
let x = 100;
fn();
}
run(log);
};
outerFn(); //1
let x0 = 0;
function fn1() {
let x1 = 1;
fn2();
function fn2() {
let x2 = 2;
fn3();
function fn3() {
let x3 = 3;
console.log(x0 + " " + x1 + " " + x2 + " " + x3);
};
};
};
fn1();//0 1 2 3
ROOM 5
ali ibrahim, noor ridha, nma shawkat, zoriana Shatkovska
Q1: its A global SCOPE
Q2: the first example is local or function scope but the second one because it is declared with "var" will be a global variable.
Q3: its function scope.
Q4: Lexical
Q5: the global scope is the outermost scope, its variables can be accessed by the inner scopes like block scope and functional scope.
Q6: the var declaration declares the variable globally regardless of the block scope but the let declaration allows to declaration of variables that are limited to the scope or the block statement.
Q7: in the strict mode for example if you intentionally or unintentionally make a mistake in a code it can't be run but for sloppy mode, it can be run