Why does Chrome debugger get undefined when accessing variables in Closure? [duplicate] Why does Chrome debugger get undefined when accessing variables in Closure? [duplicate] google-chrome google-chrome

Why does Chrome debugger get undefined when accessing variables in Closure? [duplicate]


You are a first-hand observer of the internal mechanics of scope-optimization. Scope optimization is checking to see which variables are used in the current scope and optimizing out access to unused variables. The reason for this is because in the machine code generated from JIT compilation of javascript, the whole concept of variable naming is lost. But, to maintain javascript compliance, the JIT compiler associates an array of used local variables to each javascript function. Observe the following code.

(function(){  "use strict";  var myVariable = NaN; // |Ref1|  var scopedOne = (function(){    var myVariable = 101; // |Ref2|    return x => x * myVariable;  })();  var scopedTwo = (function(){    var myVariable = -7; // |Ref3|    return x => x / myVariable;  })();  console.log("scopedOne(2):  ", scopedOne(2));  console.log("scopedTwo(56): ", scopedTwo(56))})();