How to debug JavaScript?17 Mar 2025 | 4 min read Before understanding 'how to debug JavaScript', we have to understand the term "debugging". What is Code Debugging?While coding or writing the program, we can make many mistakes, such as logical errors, syntax errors, etc. A debugging allows us to find the location/point where an error has occurred because in the debugging, we can execute our code as one line at a time. Once we find the point where we have made a mistake, we can make appropriate changes to correct the mistakes. The debug tools also allow us to make temporary changes to the program's code. This entire process of correcting a code after finding out the errors is known as debugging. In short, we can say that Code Debugging is a process of finding and correcting the programming errors. JavaScript DebuggersAs it is evident that debugging is not an easy task because it requires a lot of practice and experience, so fortunately all modern web-browsers have their own built-in Debuggers. The web-browser gives us the control to turn on or off the Debugging whenever we wanted to use it and it also allows us to set breakpoints (where the execution of the program's code can stop) and we can examine the variable when the code is executing. Generally, we can open the built-in JavaScript debugging with F12 Key to display the JavaScript values by using "console". The console.log () Method We can use the console.log() method for displaying the JavaScript values only if the browser supports debugging. Syntax of console method We can understand it more clearly with the help of an example: Program How to set breakpoints? While using a debugging, we can set the breaking points in the program's code of the JavaScript. When the control reaches any breaking point, the execution of the program gets stopped and allows us to examine the JavaScript values. Once we examined the JavaScript values and are satisfied, we can resume the execution of the program by pressing the play button. The debugger Keyword We can stop the execution of the program on any line by using the "debugger;" keyword. However, this keyword will work only if the debugger function is available. Also, we can check the JavaScript values if the debugger function is available. Once we are done with examining the JavaScript values, we can resume the execution and can search for other mistakes to correct them. Syntax Program Explanation of programIn above program, we have created a variable x in which we have multiplied 15 into 5 and used the debugger keyword for setting up a breaking point. When we perform the debugging process, the execution of program will stop at that line, and we can examine the value. If any changes are not required, then we can resume the execution. Let's see an example with practical
![]() Let us see how you can open the console on different modern browsers These are the following five major modern browsers that support debugging. Chrome
Firefox
Edge
Opera
Safari
Next TopicHow to Enable JavaScript on Android |
In order to select all the checkboxes of a page, we need to create a selectAll () function through which we can select all the checkboxes together. In this section, not only we will learn to select all checkboxes, but we will also create another...
2 min read
? JavaScript is a client-side scripting language and one of the most efficient, commonly used scripting languages. The term client-side scripting language means that it runs at the client-side( or on the client machine) inside the web-browsers, but one important thing to remember is that client's...
3 min read
Sorting characters in a string is a common task in programming, especially in web development. In JavaScript, there are various ways to sort characters in a string. In this article, we will explore some of the most popular techniques to sort characters in a string...
3 min read
JavaScript does not offer any specific in-built function to traverse the array elements/objects. You can traverse an array simply using for loop or directly by element index. An array contains multiple elements of the same type, which can be traverse using for loop. In this chapter,...
7 min read
Text to Particles Dissolve Effect JavaScript & CSS In this article, we will understand how to create example of text to particles dissolve effect by using JavaScript & CSS. Particles dissolve effect is used for creating animated, interactive, configurable particle animations on a Canvas element that...
6 min read
JavaScript confirm method invokes a function that asks the user for a confirmation dialogue on a particular action. The confirm () method uses a window object to invoke a dialogue with a question and two option buttons, OK and Cancel. If the user selects the...
3 min read
A 2D drawing context's translate() method is used. The canvas and its origin are moved by x and y units using the translate(x,y) method. Otherhand, The drawing position (0,0) on the canvas is remapped by the translate() method. The value is included in the x- and...
6 min read
? A JavaScript function is a block of code that consists of a set of instructions to perform a specific task. A function can also be considered as a piece of code that can be used over again and again in the whole program, and it...
5 min read
When a user tries to load a page but it is unsuccessful, the page remains unloaded, and a JavaScript onunload event is triggered. The possibility exists that the onunload event will also happen if the browsers have been closed while the page is loaded. When a...
3 min read
In JavaScript, the italics() method is used to display an italic string. It makes the text similar to the text is in <i> </i> (italic tag). Because the italics() method is a method of string object, so it must be invoked through a specific instance...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India