Visual Studio CodeJavascriptDebugging
Last updated at 2023-09-08

Javascript Debugging in Visual Studio Code

AI Status
Last Edit By
Last edited time
Sep 8, 2023 10:11 AM
Sep 8, 2023
Visual Studio Code
Debugging is an essential skill for any developer. It allows you to find and fix issues in your code, making the development process smoother and more efficient.
Visual Studio Code (VS Code), a popular code editor, provides robust debugging capabilities for JavaScript developers.
In this beginner's guide, we'll walk you through the steps to start debugging JavaScript code in Visual Studio Code.


Before we dive into debugging JavaScript code in VS Code, make sure you have the following prerequisites:
  1. Visual Studio Code: Download and install Visual Studio Code if you haven't already.
  1. JavaScript Code: Have a JavaScript project or file that you want to debug. You can create a new JavaScript file or use an existing project.

Setting Up a JavaScript Project

Before you can start debugging, you need to create or open a JavaScript project in Visual Studio Code. Follow these steps:
  1. Open Folder: Open the folder containing your JavaScript project in VS Code. You can do this by selecting File > Open Folder... from the menu.
  1. Create a JavaScript File: If you don't have a JavaScript file yet, create one by right-clicking on the folder, selecting New File, and giving it a .js extension, e.g., my_script.js.
  1. Write Code: Write your JavaScript code in the newly created file.

Debugging JavaScript Code

Now that you have your JavaScript project set up, let's learn how to debug it in Visual Studio Code.
  1. Set Breakpoints: To debug your JavaScript code, you'll need to set breakpoints. A breakpoint is a marker that tells the debugger to pause the program's execution at a specific line of code. Click in the gutter to the left of your code to set a breakpoint (or use the shortcut F9).
  1. Start Debugging: Press F5 or click the green triangle icon in the top-left corner of VS Code to start debugging. This action launches your JavaScript script in debug mode.
  1. Debugging Panel: When your script hits a breakpoint, the debugging panel will appear at the top of the window. Here, you'll find buttons to control the debugger, including step in, step out, continue, and stop.
  1. Inspect Variables: While debugging, you can inspect the values of variables by hovering over them in your code or by viewing them in the Variables panel in the debugging panel.
  1. Continue Execution: To continue execution until the next breakpoint, press F5 or click the "Continue" button in the debugging panel.
  1. Step Through Code: You can step through your code line by line using the "Step Over" (F10) and "Step Into" (F11) buttons in the debugging panel.
  1. Stop Debugging: When you've finished debugging, press the red square icon in the top-left corner or Shift+F5 to stop debugging.

Configuration Settings

You can customize the behavior of the JavaScript debugger in VS Code by modifying the .vscode/launch.json file in your project folder.
This file allows you to configure how your JavaScript script runs and what debugger options are enabled.
For example, you can specify the Node.js interpreter to use, command-line arguments, environment variables, and more.
VS Code provides a graphical interface for creating and editing these configurations.


Debugging is an essential skill for JavaScript developers, and Visual Studio Code makes it easy for beginners to get started.
By following the steps outlined in this guide, you can effectively debug JavaScript code in VS Code, making it easier to identify and resolve issues in your projects.
Happy coding and debugging!

Discussion (0)

Related Posts