What is the life cycle of let variable in JavaScript

2 Answers

0 votes
let b = true;
if (true) { 
    // console.log(b); // ReferenceError - Cannot access 'b' before initialization

    let b; 
    console.log(b); // undefined

    b = 8974;
    console.log(b); // 8974
}
console.log(b); // true




/*
run:
 
undefined
8974
true
    
*/

 



answered Mar 15, 2020 by avibootz
0 votes
if (true) { 
    const f = function () {
        console.log(n);
    };

    let n = 436; 
    f(); // called after len n = 436
}




/*
run:
 
436
    
*/

 



answered Mar 16, 2020 by avibootz

Related questions

4 answers 312 views
1 answer 150 views
1 answer 134 views
1 answer 138 views
1 answer 136 views
1 answer 201 views
...