Skip to main content

Timeline for Getting All Variables In Scope

Current License: CC BY-SA 2.5

10 events
when toggle format what by license comment
May 1 at 15:50 comment added durette I came to this question to solve an XY problem. I was hoping that if I could capture every variable in scope and store their names and types, I could later run it again and compare the results, making sure that no old variable has since changed its type. I was hoping to hack up a crude way to do strong type checks at runtime.
Jul 11, 2019 at 16:10 comment added jcf Thanks, this may be useful if you need to inspect if some variable exists and how it is defined in an environment that is very complex or was designed by other people.
Sep 14, 2017 at 17:03 comment added Justin Johnson It's not the computer, it's the JavaScript language. A lot of languages don't have that feature. In fact, although there are probably others, the only one I can think of that does is Python.
Sep 13, 2017 at 8:33 comment added Pacerier @Justin, An even better question is why would the computer not allow us to know what variables are in scope?
Apr 26, 2017 at 15:20 comment added Michael Another reason to want to know what variables are in local scope is to serialize a closure.
Sep 27, 2015 at 11:13 comment added Dexygen Why shouldn't somebody at least want to check what variables are in scope, during debugging and/or development purposes.
Jun 10, 2015 at 20:30 comment added timctran I added a line checking for hasOwnProperty. For example: for ( var i in window ) { if (window.hasOwnProperty(i)) { console.log(i, window[i]); }}. This will at least cut down the inherited properties and your variables will be among only about 50 other properties.
Jan 10, 2014 at 2:54 comment added Ivan Castellanos Just change the word "window" for "global" if you're using node... or you can use the word "this" but that's prohibited under "use strict"
Jun 19, 2012 at 9:21 comment added Radu Simionescu I think the question was more general and not restricted to javascript in the context of a web browser.
Jan 12, 2010 at 21:12 history answered Justin Johnson CC BY-SA 2.5