How to Evaluate Expressions in VS Code Debug Console

Debugging code often requires inspecting variables and testing expressions in real-time. This article provides a quick, step-by-step guide on how to use the Debug Console in Visual Studio Code (VS Code) to evaluate expressions, execute code snippets, and inspect variables while your application is paused at a breakpoint.

Step 1: Start a Debug Session and Set a Breakpoint

To evaluate expressions, your application must be running in debug mode and paused.

  1. Open your code file in VS Code.
  2. Set a breakpoint by clicking to the left of the line numbers where you want to pause execution.
  3. Start debugging by pressing F5 or selecting Run > Start Debugging from the top menu.
  4. Trigger the code execution so that VS Code pauses at your breakpoint.

Step 2: Open the Debug Console

Once your execution is paused, you need to access the Debug Console interface.

The Debug Console panel will appear at the bottom of your VS Code window.

Step 3: Evaluate Expressions

At the bottom of the Debug Console, you will find an input prompt indicated by a right angle bracket (>).

  1. Type your expression: Enter any valid variable name, mathematical operation, or code statement relevant to your programming language (e.g., user.getName(), x + y, or myArray.length).
  2. Execute: Press Enter.
  3. View the result: The console will immediately display the evaluated result directly above your input line.

Key Features of the Debug Console