Murad Sofiyev
Murad Sofiyev

Reputation: 791

Javascript declare variable in global scope shorthand

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;

Upvotes: 0

Views: 70

Answers (1)

squeekyDave
squeekyDave

Reputation: 962

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.

Upvotes: 2

Related Questions