<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 8 :- Mustafa M. ,Sara Bakr , Amal Salah , Huda Hamid ,Mhamed Othman
1- global scope
2- it's global because we call it outside the cerly bracketsand they use let to declare it. in the second one they use var so it will be global and you have access for it in all level of scope
3-functional scope .
4- nested scope.
5- it's accessible and you can call it everywhere inside your script's , and it's not private for function .we use it when many function's need it to have accessible for it .
6-difference between them is that var is function scoped and let is block scoped .
7- Strict mode throws some errors which are turned into silent errors in sloppy mode. Sometimes the strict mode codes run faster than identical sloppy mode codes because fixing mistakes becomes more difficult for JavaScript engines to perform any optimization.