Answer the question
In order to leave comments, you need to log in
How to properly debug JS?
Hello. I have been working with JS for a long time, but I never learned how to debug it correctly. How can I find out where the error occurred? If everything is simple with php - it displays errors on the screen and writes them to the logs, then what about JS. If I need to see if a variable has the correct value, then every time I print it to the console using console.error? And if the DOM element is incorrectly specified, how do you know?
Answer the question
In order to leave comments, you need to log in
How can I find out where the error occurred?console.error displays the complete call stack with links to specific lines of specific scripts.
Chrome Developer Tools have all the necessary tools for debugging.
If you want to stop code execution in a specific place and look at the entire stack, then the easiest way is to use the debugger keyword:
function foo (bar) {
var a = 1;
// some code...
debugger;
// some code...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question