You are currently viewing How to Read a JavaScript Stack Trace in Chrome DevTools
Follow the throw to the caller that supplied the value.

How to Read a JavaScript Stack Trace in Chrome DevTools

Start with the error message and click the first stack frame that points to code you own. Read the highlighted expression, then follow the next relevant caller frame to see what it can tell you about the value. That is how you separate the line where the program failed from the line that explains why it failed.

Produce a trace you can follow

Save the following as stack-demo.html and open it in Chrome. Open DevTools and select Console before clicking Show total. The example runs in the browser by itself.

<!doctype html>
<meta charset="utf-8">
<title>Stack trace demo</title>
<button id="show">Show total</button>
<script>
  function formatTotal(value) {
    return value.toFixed(2);
  }

  function showTotal() {
    const total = "12.50";
    document.querySelector("#show").textContent = formatTotal(total);
  }

  document.querySelector("#show").addEventListener("click", showTotal);
</script>

The console should show a TypeError involving toFixed. Expand the console entry if the frames are collapsed. Chrome places a clickable source location beside the frames it displays. The exact message and display depend on the browser version. See the Chrome Console reference for the UI.

Chrome Console shows the real TypeError from stack-demo.html.
Expand the error to see which function called formatTotal.

Read the top frame, then move one frame down

The top application frame is formatTotal. It shows the expression that was tried to be used toFixed. The next frame isshowTotal, where formatTotal(total) was called. That caller assigned a string to total. The quotes in the demo are the reason total is a string even though it looks like a number.

If you only look at the throwing line, you can tell that something is wrong with the method call. The caller gives you the value’s origin. In a bigger page, carry this distinction back through more frames until you reach the point where your code decided what value to pass.

Pause where the value still exists

In Sources, place a breakpoint on the line that returns value.toFixed(2) and click the button again. The debugger stops before the expression runs. Find value in Scope, or type typeof value in the Console while paused. It should be "string". Choose showTotal in the Call Stack to inspect its local variables instead.

DevTools Scope shows the local value as a string while execution is paused.
Check the argument while the throwing expression is still paused.

Resume execution, fix the assignment by changing "12.50" to the number 12.5, and reload the page. With the breakpoint disabled, a click should change the button text to 12.50. Clear the old error from the Console or note its timestamp before comparing a new run. Chrome’s debugging reference covers local values and call frames.

Handle an unfamiliar frame

If several frames belong to a framework, start with the first identifiable application function and look at how it was called. Chrome can hide ignore-listed frames. Expand them when the transition between application and library matters. If the source location points to a minified bundle, check whether a source map is available and loaded. A source map can guide you to the authored file, while a formatted bundle still represents the published code.

A trace is a record of how execution reached a point. It gives you a good direction for investigation, even when the value arrived from a form or a request earlier. Use the scope and caller to check how that input was interpreted. If the failure begins while waiting for an HTTP response or reading its body, follow with the network waterfall guide.

Identify what kind of line you are looking at

An error entry often starts with an error type and a message. Read those before opening a source link. The message tells you what the runtime noticed. Here the message concerns a method that cannot be called on the value it received. In this demo, the first visible frame marks the attempt. On another page, an ignored frame or a rethrown error can change what you see first. You need both pieces to decide which value to inspect.

Each following frame gives a function or source location that was part of the recorded execution path. In the demo, the first location is the formatter and the second is its caller. Read a location as a file, line, and sometimes a column. A column is particularly useful when a line contains several calls. Click through, then look at the nearby expression and its inputs rather than stopping at the filename.

The exact presentation can change across environments. MDN’s Error stack reference describes differences between JavaScript engines. In Chrome, rely on the names and source links you can see in the Console instead of assuming that a line pasted from another browser will have precisely the same form.

Work through the demo with a specific question

At the throwing frame, ask what would have to be true for this expression to work. Here the formatter expects a number with a callable toFixed method. A string containing digits is still a string. If you pause at the expression, the value in Scope lets you check that distinction before execution changes.

Then ask which code decided to call the formatter with that value. Select the caller frame. Scope now reflects the selected call, which makes it easier to compare the caller’s local total with the callee’s value. They describe the same input as it moved from one function to the other. The line where total was set tells you why this copy of the demo fails.

In a real application, that value might have come from an input field, a request body, or a string read from storage. The appropriate fix depends on the contract. If a form always yields text and the formatter expects a number, validate and convert near the form boundary. If an API promises a number and sometimes sends text, check that API boundary before quietly accepting everything. The demo changes the assignment itself because there is one known constant and no external input to validate.

Use the caller even when the top frame is in a library

The first frame you own is a practical point of entry. It may show the configuration, callback or data your application gave a library. If the trace starts inside library code, record the first few frames as well as the one you recognize. The library’s caller and the application frame can tell you where to set a breakpoint.

Chrome’s debugging reference describes showing ignore-listed frames while paused. Expand them when you need to see what connects two application functions. Collapse the extra detail once you know where to inspect. If you see two similarly named application functions, follow the source paths and line locations before deciding which one ran.

The source location opens a bundle

Look for authored sources in the Sources panel and check whether the deployed site supplied source maps. When the authored file is available, confirm that its line corresponds to the failing expression. If a source map is unavailable, inspect the deployed expression or pause at a point you can reproduce. Treat pretty printing as a reading aid for deployed code. It can add line breaks but cannot recreate original variable names or reconstruct a missing source map.

stack-output-fixed

The trace includes an asynchronous step

An event, a promise continuation, or other asynchronous work can put distance between the place that scheduled work and the place that failed. DevTools can show async frames when the relevant context is available. Follow visible frames, then use a breakpoint at the start of the callback or at the data boundary if the earlier context is missing. Reproduce the concrete action and record whether the error appears immediately at the click or after a later operation finishes.

Decide when to pause on exceptions

When you can reproduce the failure on demand, and the trace points to a clear location, a line breakpoint is enough. Use pause on exceptions when the failing line is unclear, or the surrounding code catches an error before you can see the inputs. If the page stops repeatedly inside unrelated code, narrow the scenario and use the available controls for caught or uncaught exceptions to reduce interruptions. Chrome DevTools breakpoint guidance covers those settings.

While paused, inspect values before you consider changing them. A debugger edit can help test a hypothesis, but verify the correction on a clean reload using the application source. That check tells you whether the next user will get the same result without a manual change in DevTools.

Save a useful record of the fix

Include the action that triggered the error, the first meaningful source location, and the value or type you confirmed. The MDN debugging walkthrough illustrates how debugger observations help narrow a bug. For this example, a useful record gives the button action, both relevant functions, and the string type you saw in Scope. If the same browser tab contains old error entries, clear them and take one fresh reading of your corrected run before writing the result.

Check whether the error you see matches the action you just took

A page can log warnings on load and errors later when you click. Clear the Console, reload the demo, and see what appears before touching the button. Then click once. A fresh entry at that point is easier to connect with the action. If nothing appears, check that the level filter allows errors, that the Console is showing the target page, and that the button really calls the function in your current saved file. Try with the demo open in its own tab so you can see which document is running.

When the same error appears twice, consider whether two listeners or two actions are involved. Set a line breakpoint inside the caller and count how many times it stops for one click. If it stops twice, inspect the two stacks before you fix the formatter. You may have an independent issue in the way the callback is registered. Keep that observation separate from the confirmed string value. The type fix should clear the original error, while the extra invocation deserves its own reproduction if it matters to the page’s behaviour.

If the display changes to 12.50 after the fix, reproduce it again from a fresh reload. Make sure the browser loaded the edited copy, especially if you opened several similarly named demo files. One clean error run and one clean fixed run are enough to show what changed.

At the end of the demo, you should have two pieces of evidence: the thrown expression tried to format a number, and its caller passed a string. Keep that same pair in a bug report. It gives the next person a specific value and call to inspect.