How can I determine the current line number in JavaScript?

Matthew Murdoch picture Matthew Murdoch · Feb 26, 2010 · Viewed 65.7k times · Source

Does JavaScript have a mechanism for determining the line number of the currently executing statement (and if so, what is it)?

Answer

z5h picture z5h · Feb 26, 2010

var thisline = new Error().lineNumber

If that doesn't work in whatever environment you're using, you can try:

var stack = new Error().stack

Then hunt through the stack for the line number.