Retrieving values from Execution Contexts in JavaScript

前端 未结 6 992
长发绾君心
长发绾君心 2021-01-27 15:40
var value = 10;

var outer_funct = function(){
    var value = 20;

    var inner_funct = function(){
        var value = 30;

        console.log(value); // logs 30
            


        
6条回答
  •  梦谈多话
    2021-01-27 16:03

    var value = 30; is a local variable in function outer_funct, it could not be accessed from outside of this function.

    in your code, although winodw["outer_funct"]["value"] is written inside inner_funct but it acts as trying to access a local variable from out of outer_funct because by `window['outer_funct'] you are staying at the top level.

提交回复
热议问题