Moon Light Box

Time is Money

JavaScript - Closure

| Comments

var scope = 'global';
if(true){  
    var scope = 'local';  
    console.log(scope)  --> local
}  
console.log(scope); --> local
var scope = 'global';  
function foo(){  
    var scope = 'local'; 
    console.log(scope);  --> local
}  
foo(); 
console.log(scope);  --> global

https://cnbin.github.io/blog/2017/04/11/jszhong-de-bi-bao/

http://carlos-studio.com/2013/09/06/js-%E9%97%9C%E6%96%BC%E5%87%BD%E5%BC%8F/

https://openhome.cc/Gossip/JavaScript/Closure.html

Comments

comments powered by Disqus