snapshot of code inside chrome dev tools debugger
As seen from the above snapshot, the variable "age" exists in the local scope but outside the window object. Why does it happen? Is there any in-depth explanation to it.
I checked the values and scope state using chrome dev tools debugger.
2
Answers
Local variables do not show up as
window
properties. Local variables are variables defined in the scope of functions. On the other hand, global variables are available as properties ofwindow
.Variables declared under function have function scope only.
But, Variables declared with var at the global scope, however, do become properties of the window object in browsers, but this behavior doesn’t apply to variables declared inside function scopes.