find dead JavaScript code?

JoelFan picture JoelFan · Nov 9, 2010 · Viewed 30.5k times · Source

We are refactoring a legacy web app and as a result are "killing" quite a lot of JavaScript code but we're afraid of deleting what we think is dead code due to not being sure. Is there any tool / technique for positively identifying dead code in JavaScript?

Answer

Julio Santos picture Julio Santos · Nov 9, 2010

There's grep. Use it to find function calls. Suppose you have a method called dostuff(). Use grep -r "dostuff()" * --color on your project's root directory. Unless you find anything other than the definition, you can safely erase it.

ack is also a notable alternative to grep.