Overview of Debugging JavaScript in Chrome

As a new JavaScript programmer, Searching and correction of the bugs can be difficult. You can use built-in JavaScript functions for error correction through chrome. A simple example of finding and fixing errors in JavaScript is console.log() function that helps to get your code working correctly. Not Anymore!

► Play

This article is all approximately debugging the precise manner! You’ll learn how to use the Chrome Developer Tools to set up breakpoints and step-thru your code. This workflow is often a much greater green way to find and connect insects for your code. This academic suggests you a way to debug one particular issue, but the standard workflow you examine is useful for debugging all forms of JavaScript insects.

Debug the code through Breakpoints

In JavaScript code, you can easily find errors in chrome using different breakpoints. DevTools lets you pause your code within the middle of its execution, and examine the values of all variables at that second in time. The device for pausing your code is referred to as a breakpoint.

► Play

Let’s you break the code using on click function:

onClick()

We add this function in any HTML tag and define it in JavaScript file or internal js.

  • Open the Chrome browser.
  • Shortcut key [ Control + Shift + I ] in chrome for both windows and Linux operating systems.
  • Click on Source option or menu in chrome browser.
  • Select Event Listener Breakpoints and open it. Now DevTools will expand event categories, Animations and clipboard.
  • Now check the mouse event option and open it.

You can check click checkbox.

Debugger Keyword in JavaScript

Similarly, breakpoints debugging you can also use debugger statement for stopping or breaking the JavaScript code.
JavaScript functions with debugger keyword.

► Play

function hello ( name ) {

let phrase = “ Hello , ${name}! ” ;

debugger ; // <– the debugger stops here

say ( phrase ) ;

}

That’s very handy whilst we’re in a code editor and don’t need to replace to the browser and appearance up the script in developer equipment to set the breakpoint with debugger keyword.

How to Debug JavaScript in Chrome Android

Previously, console logging becomes a pleasant alternative for debugging JavaScript on Android. These days with Chrome for Android faraway debugging, we’re capable to make use of all the goodness of the Chrome for Desktop Developer Tools on Android.

► Play

You also can navigate too approximately: debug inside the URL bar to prompt the debug menu and the JavaScript mistakes console with current Android devices. You need to see SHOW JAVASCRIPT CONSOLE at the top of the Browser. Currently in Android 4.0. Three (Ice Cream Sandwich), the logcat outputs to the browser channel

Send us a feedback0/500

Do you like this article?
Yes
No