0

When I execute this code:

var A_RANDOM_VARIABLE; // I've made it capitalized because it's easier to spot 
// in the output
console.log(window);
A_RANDOM_VARIABLE = "I have a value";

I expect to see "undefined" when I click that triangle button to expand the content of the window object. But I actually get the value "I have a value"

enter image description here

What happens here? Could anybody explain it to me?

Latika Agarwal
  • 973
  • 1
  • 6
  • 11
BoSsYyY
  • 563
  • 5
  • 13
  • 2
    The console is "live", you see the current state of an object. Do `console.log(JSON.stringify(window))` to get what you expect. – Jonas Wilms May 26 '18 at 11:12
  • This actually has nothing to do with the global object. :-) See the linked question's answers and Jonas' comment above. You'd see the same thing with `var obj = {name: undefined}; console.log(obj); obj.name = "I have a name";` – T.J. Crowder May 26 '18 at 11:14

0 Answers0