Friday, February 12, 2021

Debugger statement in JavaScript



The debugger statement stops the execution of JavaScript, and calls (if available) the debugging function.

Using the debugger statement has the same function as setting a breakpoint in the code.

Normally, you activate debugging in your browser with the F12 key, and select "Console" in the debugger menu.

Note: If no debugging is available, the debugger statement has no effect.

- - -

We have written this JS code in an HTML file:


<script>
function outer(){
    console.log("From outer")
    inner()
} 

function inner(){
    debugger;
    console.log("From inner")
    alert("Bye")
}
</script>

<body onload="outer()"> </body>



- - -

Following are the screenshots of "Firefox Debugger" when we run this code:

When we would press on "Play" button in "Debugger", it will end on the last "alert()" statement.

No comments:

Post a Comment