Sitemap

Quick Guide to Debugging in Javascript

3 min readMar 27, 2019

--

Press enter or click to view image in full size
Courtesy of Unsplash

I have been working on Stephen Grider’s Javascript Udemy course, The Coding Interview Bootcamp: Algorithms + Data Structures, and there is a helpful part in the course where he talks about the basics of how to debug as you are working on solving the different algorithms in his course. I wanted to create this quick guide breaking down the steps of how to do it here.

  1. Place the debugger statement in your code where you would like it to be paused.
Press enter or click to view image in full size

2. Make sure if the debugger is in a function to call the function.

Press enter or click to view image in full size

3. Launch your javascript file in debugger mode by using the terminal to navigate to the directory the file is in and running node inspect your-file-name.js. It will pause its execution on the very first line of the file.

Get Jordan Martin’s stories in your inbox

Join Medium for free to get updates from this writer.

Press enter or click to view image in full size

4. Tell the inspect to continue running the code by typing c (or cont). It will then execute the file line by line and pause once it finds the first debugger statement.

Press enter or click to view image in full size

5. Enter the REPL mode to start a Javascript console by typing repl.

Press enter or click to view image in full size

6. Test out your code! You are now in a Javascript console and can check the value of variables or run later written code to make sure you are getting the results you expect.

Press enter or click to view image in full size

7. Exit REPL mode by hitting control + c. If needed, you can move on to the next debugger by entering c (or cont) repeating steps 4–6. If the code runs until the end then you can hit control + c again to exit the debugger mode.

Press enter or click to view image in full size

--

--