DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. JavaScript
  4. JavaScript: Break Your Code With the Debugger Statement

JavaScript: Break Your Code With the Debugger Statement

Learn about using the debugger statement in JavaScript, one of the most common ways of performing client-side debugging with this library.

Raghuraman Kesavan user avatar by
Raghuraman Kesavan
·
Aug. 23, 17 · Tutorial
Like (5)
Save
Tweet
Share
12.45K Views

Join the DZone community and get the full member experience.

Join For Free

In this post, we will learn more about the debugger statement available in the JavaScript library. Many JavaScript developers may not aware of the debugger statement. I generally believe that most JavaScript developers use any of the below four methods for client-side debugging:

  • console.log() Statement
  • Setting breakpoint using developer tools available in the browser (preferred)
  • Debugger Statement
  • alert statement (mostly beginners will use this)

Here, we are primarily going to talk about the debugger statement. Before that, the console object provides access to the browser's debugging console and has many inbuilt methods available with it. Some of the example methods are

console.trace();
console.warn();
console.log();
console.info();
console.error();
console.clear();


You can use these methods to differentiate the console message. Check this URL to learn more about console objects.  

Debugger Statement

The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.

Syntax:

 debugger; 

Code:

function potentiallyBuggyCodeAvailable(){
   code;
   debugger;
}


When the debugger is invoked, execution is paused at the debugger statement. It is like a breakpoint in the script source.

Javascript Debugger

In the above code, when the submit button is clicked it, will call sum() method  and the code will break where the debugger statement is added.

In the above screenshot, the code was broken where the debugger statement is added. It will be really helpful under certain circumstances.

Next Article : [Javascript] Exception Handling with Try...Catch Block

If you enjoyed this article, please share it with your developer friends on social media.

JavaScript

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Image Classification With DCNNs
  • (Deep) Cloning Objects in JavaScript
  • Best Practices for Writing Clean and Maintainable Code
  • How to Configure AWS Glue Job Using Python-Based AWS CDK

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: