Debugging JS

Spanish audio is available in the player settings
Rate this content
Bookmark

As developers, we spend much of our time debugging apps - often code we didn't even write. Sadly, few developers have ever been taught how to approach debugging - it's something most of us learn through painful experience.  The good news is you _can_ learn how to debug effectively, and there's several key techniques and tools you can use for debugging JS and React apps.

This talk has been presented at React Summit 2023, check out the latest edition of this React Conference.

Watch video on a separate page

FAQ

Mark Ericsson's talk focuses on debugging JavaScript, emphasizing the importance of this skill and sharing insights and techniques for effective debugging.

The slides from the presentation can be found on Mark Ericsson's blog at blog.isquaredsoftware.com.

Redux Toolkit 2.0 Beta is an update that focuses on modernizing the package formatting and contents, removing deprecated APIs, and adding new APIs. Mark Ericsson encourages users to test it in their applications and provide feedback.

Core principles include understanding the system's intended function, reproducing the issue, and systematically testing changes to pinpoint the problem. It's also important to interpret error messages and use them to guide debugging efforts.

Mark recommends using both print statements and graphical debuggers. Print statements help track changes over time, while graphical debuggers allow for step-by-step code inspection and interaction.

Replay works by recording browser sessions that can be inspected later using time travel debugging. It's beneficial for understanding bugs as it allows developers to review the exact state and sequence of events leading to an issue.

Yes, Replay can record any JavaScript application running in a browser, regardless of the framework used. It also offers specific integrations for popular frameworks like React.

The key steps include understanding the bug report, reproducing the issue, identifying why it's happening, determining the best solution, implementing fixes, and documenting the process for future reference.

Mark Ericsson is a senior frontend engineer at Replay and a Redux maintainer. He is known for his contributions to Redux, including publishing Redux Toolkit 2.0 Beta, and for actively engaging with the tech community via his blog and online platforms.

The time-traveling debugger, developed by Replay where Mark works, allows developers to record bugs and then use time-travel debugging to analyze what happened, greatly enhancing the debugging process.

Mark Erikson
Mark Erikson
24 min
02 Jun, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
Available in Español: Depuración de JS

1. Introduction to Debugging JavaScript

Short description:

This is Mark Ericsson, and today I'm excited to talk to you about debugging JavaScript. Fair warning, I've probably got about 40 minutes of content and like 20 minutes to get through it, so I'm going to go a little bit fast. A couple of quick things about myself. I am a senior frontend engineer at Replay, where we're building a time-traveling debugger for JavaScript.

This is Mark Ericsson, and today I'm excited to talk to you about debugging JavaScript. Fair warning, I've probably got about 40 minutes of content and like 20 minutes to get through it, so I'm going to go a little bit fast.

The slides all are already up on my blog, blog.isquaredsoftware.com. Feel free to pop that open and follow along, or take a look at it later.

A couple of quick things about myself. I am a senior frontend engineer at Replay, where we're building a time-traveling debugger for JavaScript. We'll talk more about that in a few minutes. I answer questions anywhere there is a text box on the internet, I collect any link that looks potentially useful, I write extremely long blog posts, and I am a Redux maintainer, but most people know me as that guy with the Simpsons avatar.

This is not a Redux talk, but I do have one Redux-related piece of news. Two days ago while I was at the airport, I published Redux Toolkit 2.0 Beta. We have a number of things we're trying to accomplish in 2.0, most of it has to do with modernizing the package formatting and the contents of the JavaScript. We've removed a couple deprecated APIs. We have several new APIs we've added. The biggest thing I would ask is that we would really like people to try it out in your applications right now, see how it works, give us feedback, tell us what things broke, tell us if the APIs are working, so that we can move forwards towards 2.0 final. I don't have an actual timeline. I'm hoping within the next few months, hopefully, if things go well.

2. Principles of Debugging

Short description:

Debugging is the process of finding problems in your program and trying to figure out what's going on. As programmers, we spend a lot of time trying to figure out why the code we wrote is not working. I think the biggest problem is that our industry does not teach people how to debug. Every problem has a cause and a reason, and it should be possible to figure out why something is broken. It's important to understand what the system is supposed to be doing and to be able to reproduce an issue. Debugging with a plan and not panicking when encountering errors are also crucial.

All right. Let's talk debugging. Debugging is the process of finding problems in your program and trying to figure out what's going on. In other words, why is it broken? And how do we fix it?

Now, as programmers, we spend a lot of time doing things other than just writing code. We are communicating with our team. We are doing planning, design, discussions, code review. We spend a lot of time trying to figure out why the code we wrote is not working. And yet a lot of developers are not actually comfortable doing this. And I've thought about this a bit. I think the biggest problem is that our industry does not teach people how to debug. How many of you have a comp sci degree and yet never had a course in debugging? To me, debugging is an absolutely critical skill for developers. And the good news is it is something you can learn and get better at.

So, let's look at some core principles of debugging. Now, the title of the talk is debugging JavaScript. These principles are universal. You can apply them to any language and frankly you can apply them outside of programming as well. And the first is that every problem has a cause and a reason. And it should be possible to figure out why this thing is broken. Now, just because there is a cause doesn't mean it's going to be easy to figure out. And there's a lot of things that can make that more complicated. But it is possible. Another is that it's very important to understand what the system is supposed to be doing. If a bug is something is wrong with the system, you have to know what it was supposed to do in the first place to see that behavior is incorrect. Another principle is that reproducing an issue is absolutely key. For one, you need to be able to figure out what area of the code is broken, and that often requires a trial and error process of making this thing crash over and over and over but it's also important because once you think you have a fix, you need to be able to try the same steps and verify that it actually works right. You also need to be able to debug with a plan. This is basically the scientific method. Don't just go changing random variables and hoping it's somehow going to make it better. You need to be very careful and intentional about the changes you make, try one thing at a time, see if the behavior changes actually match what you expect it to be and try to narrow down where and why something is going wrong. Another issue is that errors provide useful information and yet people often panic when they see that gigantic stack trace.

Available in other languages: