
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to use the debugger keyword in JavaScript?
Whenever an unexpected occurrence takes place in a JavaScript code, we need to debug it to check the cause. Debugging is a very important aspect of programming that lets you determine why a system or application behaves abnormally. It is a process of testing multiple times with different inputs and finding errors to reduce bugs from computer programs.
In this article, we will be exploring the debugger keyword in JavaScript and how to use them. The debugger keyword in JavaScript is a common keyword used in debugging processes and variable details. In JavaScript whenever the debugger keyword is turned ON, it stops the execution of the JavaScript code and calls the debugging function if available. Else it has no effect.
Example
In the below example, we are going to use the debugger keyword to stop the program execution for the debugging process. We will describe the debugger keyword and how it actually works in detail.
# index.html
<!DOCTYPE html> <html> <body> <h1 style="color: red;"> Welcome To Tutorials Point </h1> <p id="para"></p> <p>This will stop the execution and move the context to the debugger window.</p> <script> let a = 10 * 5; debugger; document.getElementById("para").innerHTML = a; </script> </body> </html>
Output
We can see in the below output that whenever the code is executed it comes under the debugging window on encountering the debugger keyword. To continue the process, we will skip the debugger pointer by pressing the F8 button and let it execute.
Or we would move to the next line by using the “Stop over next function call” or the F10 button.
- Related Articles
- How to use void keyword in JavaScript?
- How to use the 'with' keyword in JavaScript?
- The debugger statement in JavaScript
- How to use 'const' keyword in JavaScript?
- Understanding the use of debugger in Node.js
- How do you launch the JavaScript debugger in Google Chrome?
- How to use the "defined?" keyword in Ruby?
- How to use the "not" keyword in Ruby?
- How to use the "or" keyword in Ruby?
- How to use the readonly keyword in TypeScript?
- How to force Chrome's script debugger to reload JavaScript?
- How to use the 'and' keyword in Ruby?
- How does the “this” keyword work in JavaScript?
- The Python Debugger (pdb)
- The yield* expression/keyword in JavaScript.
