0

I am looking for a tool that displays all usages of global variables (and functions) in a javascript-file.

For example, if I write to following:

function foo() {
    for(i = 0; i < 10; i++) {
        document.body.innerHTML += "<span>Hello</span>";
    }
}

Then, the output should be: i, document - even if "foo" has never been called.

Using this list, most forgotten variable declarations can be found instantly.

I tried using jslint for that (since it displays the global variables), but it is way too strict (even with all "tolerate"-settings active) and does not even parse the whole code before aborting.

Do you know any other tools that can do that?

This is NOT a duplicate of Javascript - dumping all global variables. The accepted answer there is a list of all global variables, after all code has been executed. I am looking for a parser that checks all code before execution.

Community
  • 1
  • 1
Andreas
  • 1,997
  • 21
  • 35
  • All global variables are properties of the `window` object, so you can just [list all properties of that](http://stackoverflow.com/q/208016/). However, if you're worried about forgetting global variables, you should probably not use them in the first place. – Blazemonger Jan 28 '15 at 14:04
  • 1
    Just a reminder: tool recommendation is off-topic for Stack Overflow. Take a look at JSHint – meskobalazs Jan 28 '15 at 14:05
  • 1
    No duplicate IMO. The response there only shows ways to display the values that have already been defined on the window-object. I need a tool that shows that global variables that might be created. – Andreas Jan 28 '15 at 14:08
  • 1
    Not duplicate at all, some people just scan for keywords in titles instead of bothering to read and understand questions. Still it's about a tool / software, not a programming problem, could have been closed as off-topic ;) Have you looked into http://jshint.com/ ? – pawel Jan 28 '15 at 14:15
  • Just now. I was busy explaining the "non-duplicate". jshint.com is perfect for me. Thank you! – Andreas Jan 28 '15 at 14:21

0 Answers0