I expect when I insert the JavaScript debugger statement into my JavaScript code that the program will pause at that point and the debugger will open showing the 'breakpoint'.
I'm not seeing this at all.
Here is my code.
<html>
<script type="text/javascript">
debugger;
alert("Hello world!")
</script>
<body>
<p>Hello world</p>
</body>
</html>
When I run it - I go straight to the 'alert' popup on screen. What is the step I'm missing?
My question is: Why doesn't the JavaScript debugger pause at debugger statement?
(Just to clarify - I had the developer tools open - but at the 'console' tab, not the 'sources' tab.)
The debugger statement in JavaScript is used for setting a breakpoint in the code. The code stops execution as soon as it encounters the debugger statement and calls the debugger function (if available).
What makes JavaScript great is also what makes it frustrating to debug. Its asynchronous nature makes it easy to manipulate the DOM in response to user events, but it also makes it difficult to locate problems.
It looks like Chrome won't pause at debugger;
statements when the JS code is minified. I don't have source maps set up though.
You need to open the Developer Tools
before the debugger;
is executed.
Open using F12 key (read this to learn about more features)
Developer Tools
are not opened
Developer Tools
are opened
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