Wednesday 24 October 2018

JavaScript: debugger statement

When the debugger is turned on, then debugger statement pauses the execution of JavaScript application.

HelloWorld.html
<!DOCTYPE html>
<html>

<body>

    <p>Click on the buttons to perform Arithmetic Operations</p>

    <button onclick="sum()">Add Numbers</button>

    <p id="demo"></p>

    <script>
        function sum() {
            var input1 = parseInt(prompt("Enter first Argument", 0));
            var input2 = parseInt(prompt("Enter Second Argument", 0));
            var result = input1 + input2;

            //When the debugger is turned on, then the application pauses here
            debugger;

            console.log("Sum of %d and %d is %d", input1, input2, result);
            document.getElementById("demo").textContent = "Result : " + result;
        }
    </script>

</body>

</html>

Load application in browser and turn on the debugger. After entering the inputs to the application, you can observe control stops at debugger statement.



Previous                                                 Next                                                 Home

No comments:

Post a Comment