JS advanced — sandbox

Time:2020-10-2

sandbox

 

Sandbox: environment, black box, simulate the real world in a virtual environment, do experiments, the experimental results are the same as the real world, but will not affect the real world
 
 
var num=10;
console.log(num+10);

 

//Sandbox -- small environment
    (function () {
      var num = 10;
      console.log(num);
    })();

 

//Sandbox -- small environment
    (function () {
      var num = 20;
      console.log(num + 10);
    }());

 

Inside and outside do not affect each other

    var num = 100;
    (function () {
      var num = 10;
      console.log(num);//10
    }());


    console.log(num);//100