var object = {name: "Murad"};
(function(window){
var a = b = 10;
})(object)
Why I can access b variable in global scope?
var a = b = 10
is not same thing with?
window.b = 10;
var a = window.b;
You can access variable b because you give a variable name - b, but you do not declare it like var let or const. JS will see that a name is allocated for a variable and it will create the variable automatically in the global scope.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.