A mistake in a program or a script is referred to as a bug.
Debugging is the process of testing, finding, and reducing bugs (errors) in computer programs.
Built-in debuggers can be turned on and off, forcing errors to be reported to the user.
With a debugger, you can halt your code at certain breakpoints (places where code execution can be stopped).
Once execution is halted, you can examine the state of the script and its variables in order to determine if something is amiss.
You can also watch variables for changes in their values.
If your browser supports debugging, you can use
let x = 50;
let y = 20;
let z = x + y;
To access your web browser's console, first press F12 key on the keyboard and then click on the "console" tab.
debugger keyword invokes any available debugging functionality, such as setting a breakpoint.
If no debugging functionality is available, this statement has no effect.
The following example shows code where a
debugger statement has been inserted, to invoke a debugger:
var a = 50 + 20;
document.getElementById("output").innerHTML = a;
When the debugger is invoked, execution is paused at the
debugger statement. It is like a breakpoint in the script source.
Normally, you activate debugging in your browser with F12, and select "Console" in the debugger menu.
Otherwise follow these steps: