Does JavaScript have a mechanism for determining the line number of the currently executing statement (and if so, what is it)?
The $() function The dollar function, $(), can be used as shorthand for the getElementById function. To refer to an element in the Document Object Model (DOM) of an HTML page, the usual function identifying an element is: document.
JavaScript is a single-threaded language, where only one command executes at a time. It has a Synchronous model of execution, where each line is executed line by line, top to bottom.
The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With