Thursday 25 October 2018

JavaScript: Adding Conditional break points

You can add conditional breakpoints to the application. Application pauses at the break point, when the condition evaluates to true, else not.

How to add conditional breakpoint?
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;

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

</body>

</html>

Open HelloWorld.html page in browser.

Turn on the debugger.

Add one break point, Right click on the breakpoint -> Edit breakpoint…


I added one conditional breakpoint (result >=100) while writing to the document. Application pauses its execution, when the result is > 100.









Previous                                                 Next                                                 Home

No comments:

Post a Comment