24 Dec
24Dec

When we write code in any programming language it is obvious that  errors will be occur, these errors might be logical errors or syntax errors. When search for errors and do fix them, it is called code debugging. While pursuing JavaScript course in Delhi, you will also get to know about this term.

Debugging in JavaScript is not easy but nowadays all of the modern browsers have buit in JavaScript debugger. In JavaScript we can turned off or on the built in debugger of the JavaScript.

To debug our code we use console . log ( ) ; to see the JavaScript values or errors in to the console window of the browser. Let’s see and code of debugging by using console . log ( ) ;

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<script>
a = 5;
b = 6;
c = a + b;
console.log(c);
</script>

</body>
   </html>

To see the value of the console . log ( c ); Press F12 in the browser and select the console option, in the console window we will see the value it as 11.

We can set the break points in the debugger window of the browser and set the break points in our JavaScript code. At each break points JavaScript will pause the executing and let us examine the values of code. When the examination of that part of the code is done we can resume the code execution again with the help of play button.

We can also use the debugger keyword to debug the code of JavaScript, debugger keyword will stop the execution of the code, and will resume after the code examination is done by the debugger. It will work same as that we were doing in the browser by setting the break points manually. We write in the code with the help of the debugger keyword in the code of the JavaScript.

Let’s see an example of the debugger:

<!DOCTYPE html> 

     <html> 

     <body>

          <h2>JavaScript Debugger</h2> 

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

          <p>With the debugger turned on, the code below should stop executing before it executes the third line. </p>

        <script>

           let x = 15 * 5;

           debugger;

            document.getElementById("demo").innerHTML = x;

         </script>

      </body>

  </html>


Now it is your turn to work with fixing bugs. Always remember that method of fixing bugs can be different from one language to another. So, it is recommended to learn all the important and in-demand languages of website development by joining web design course in Delhi.

Comments
* The email will not be published on the website.
I BUILT MY SITE FOR FREE USING