SpyreStudios

Web Design and Development Magazine

  • Design
  • Showcase
  • Inspirational
  • Tutorials
  • CSS
  • Resources
  • Tools
  • UX
  • More
    • Mobile
    • Usability
    • HTML5
    • Business
    • Freebies
    • Giveaway
    • About SpyreStudios
    • Advertise On SpyreStudios
    • Get In Touch With Us

The Powerful JavaScript Debugger You Never Knew You Had

February 26, 2018 by Alex Fox

When you were first starting to write JavaScript, you learned about console.log. You learned about outputting messages to the console and using it to troubleshoot your JavaScript. And unless you’re a fairly serious JavaScript developer, you might not have bothered with much more. When JavaScript apps don’t work correctly, developers are often quick to start peppering their code with console.log statements, echoing the values of expressions to the console to try and traceback an error. It’s hardly efficient, but for a simple program, it works. It probably won’t surprise you to learn that there is a better way to troubleshoot your JavaScript. Better still, there’s an awesome JavaScript debugger buried right inside your browser. You can use Firefox Quantum’s recently-revamped built-in JavaScript debugger or Google Chrome’s Sources tool to track and analyze your code and say goodbye to console.log for good.

In this post, we will be focusing on Firefox, but you can also find the same essential tools inside of Google Chrome’s DevTools. The overall layout off the debuggers is basically the same as well.

Getting Started with the JavaScript Debugger

To use the Firefox debugger, you’ll need to install Firefox. You can use the Developer Edition or the stable version, provided you have the newest version (codenamed Quantum). The Developer edition is sort of a half-way in-between Firefox Beta version, with some beta features geared specifically towards devs and a few UI tweaks. As far as we can tell, however, Firefox’s standard release channel contains all the same developer tools as Firefox Developer Edition.

We’ll be doing our debugging on a training site offered by Mozilla. Navigate to the site.

Open the Debugger by pressing Option + Command + S on a Mac or Control + Shift + S on a PC. This will slide up a pane from the bottom of Firefox’s primary window. If you’ve ever used Inspect Element before, this will be fairly familiar.

If you primarily use Chrome, you can also follow along in Chrome’s JavaScript debugger. It’s essentially the same, but it does have some cosmetic differences. Press Option + Command + I or Control + Shift + I to launch the Console in DevTools, then click on the “Sources” tab.

Once we have correct panel open in Firefox, we’ll want to click on the correct source. Navigate through the tree on the right until you’ve reached the JavaScript file you want to inspect. For your own projects, you’ll know what you’re looking at. For this project,

Using the JavaScript Debugger

If you’re not familiar with the idea behind using a debugger, you’re basically going through your code slowly and carefully inspecting the values of given expressions. This works the same whether it’s a C debugger or a JavaScript debugger.

Setting Breakpoints

In order to step through your code effectively, you need to set breakpoints. Breakpoints tell the debugger where to pause executing code for a moment, giving you the chance to inspect values.

Click on a line value to set a breakpoint. Here, we’ll set a breakpoint at line 13 by clicking on its line number.

add breakpoint
Image Source: Mozilla

Once we’ve set our desired breakpoints, try adding an item to our to do list.

javascript debugger firefox

The code will “break” at that point, pausing its execution until we manually continue through the stack. This let’s us take our time inspecting values.

Inspecting Values

To inspect the value of a given expressing in our JavaScript, we can hover over the value to see all it’s parameters. This value will be updated as we progress through our code.

hover
Image Source: Mozilla

You can also see what’s going on in the Scopes pane on the right. The top Block shows the variable assignments current in scope for the current line.

Stepping through Code

Once we’ve set some breakpoints, we’ll want to control how we move through our code. This is called “stepping” through the code, and we can do it in various ways. There’s a few tools that will help us do that. These tools are available at the top of the right-side pane.

We can take a closer look at what they do.

overview
Image Source: Mozilla

All of these tools run code one line at a time, but they behave different when they encounter functions.

Step Over: “step across” the current line. This will run the next line, executing any functions you encounter. This can automatically skip over many lines of code executing called functions.

Step In: run the code one line at a time, but navigate “inside” of any function you encounter. This allows you to quickly navigate to the contents of called functions for troubleshooting.

Step Out: exit a function that you entered with “Step In” and return to the main body of code.

Learning More

The JavaScript debugger is capable of more than the functions we’ve discussed here. You can learn more at Mozilla’s Debugger PlayGround, or dig in to their debugger documentation.

You might also be interested in the following posts:

How to Build a Firefox Extension

Best JavaScript Libraries for Building Web Interfaces

Learn Web Development With These Web Developer Courses

Filed Under: Tutorial Tagged With: coding, Firefox, Google Chrome, how to, javascript, tutorial

Recent Posts

  • 31 Fresh Design Elements for Spring and Easter
  • 10 Templates for Music Concert Flyers
  • How to Build a Web Scraper Using Node.js
  • Best PHP Books, Courses and Tutorials in 2022
  • How to Get Your First Web Design Client

Archives

  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • May 2008
  • April 2008

Categories

  • Accessibility
  • Android
  • Apps
  • Art
  • Article
  • Blogging
  • Books
  • Bootstrap
  • Business
  • CSS
  • Design
  • Development
  • Ecommerce
  • Fireworks
  • Flash
  • Freebies
  • Freelance
  • General
  • Giveaway
  • Graphic Design
  • HTML5
  • Icons
  • Illustrator
  • InDesign
  • Infographics
  • Inspirational
  • Interview
  • Jobs
  • jQuery
  • Learning
  • Logos
  • Matrix
  • Minimalism
  • Mobile
  • Motion Graphics
  • Music
  • News
  • Photoshop
  • PHP
  • Promoted
  • Rails
  • Resources
  • Showcase
  • Tools
  • Tutorial
  • Twitter
  • Typography
  • Uncategorized
  • Usability
  • UX
  • Wallpapers
  • Wireframing
  • WordPress
  • Work

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

SpyreStudios © 2022