Exploring closure: Environment

by Cristi Salcescu

JavaScript

(function autorun(){
    let x = 1;
    function log(){
      console.log(x);//1
    };
    
    function run(fn){
    	let x = 100;
      fn();//1
    }
    
    run(log);
})();