Categories
JavaScript Answers

How to determine the current line number in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *