Sometimes, we want to determine the current line number in JavaScript.
In this article, we’ll look at how to determine the current line number in JavaScript.
How to determine the current line number in JavaScript?
To determine the current line number in JavaScript, we can get the lineNumber property from an Error object.
For instance, we write
const thisLine = new Error().lineNumber;
to create a new Error object and get the lineNumber property from it to get the line number of the current line.
Conclusion
To determine the current line number in JavaScript, we can get the lineNumber property from an Error object.