global
is an object containing any global variables (at least in Node.js, they're in window
in the browser).
Is there a similar variable that represents the current scope? Local variables don't show up in global
(for a good reason :) )
asdf = "hello";
var local = "hello";
console.log(global); // includes asdf
console.log(???); // includes local?
Yes. There is.
No. You can't.
Why?
JavaScript has only function scope - which is the execution Context. Within the execution Context, an Activation object(also known as call object
) is used to create local variables as its property. However,
...it is not a normal object as it has no prototype (at least not a defined prototype) and it cannot be directly referenced by javascript code.
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With