The browser console is the quickest place to see JavaScript exceptions, logged values, and test expressions from the page that is currently failing. It is especially useful when a click handler, form submission, or small script behaves differently in the browser than it does in source review.
Console debugging is clearer when it stays tied to one reproducible action. Keep the affected tab open, reproduce the failure once, and use the newest error, stack frame, and page variables before adding broad logging or changing unrelated code.
A cart total function that receives JSON text instead of an array keeps the investigation small without requiring a framework. The same approach applies to form handlers, fetch callbacks, and component code: identify the thrown error, inspect the live value, test the smallest corrected expression, and reload the page to prove the original action no longer fails.
Keep the page on the same route, user state, and input values that trigger the failure.
Chrome and Edge use Command+Option+J on macOS or Ctrl+Shift+J on Windows and Linux for the Console shortcut. Firefox and Safari expose the same debugging surface with slightly different labels.
In Chrome DevTools, open Console settings and tick Preserve log so messages remain visible after the page changes.
> totalCart() Uncaught TypeError: cartItems.reduce is not a function
The error name points to the operation that failed. Here, reduce() exists on arrays, so the next check should confirm what cartItems actually contains.
> typeof cartItems "string"
> cartItems
"[{\"name\":\"Desk lamp\",\"price\":20,\"quantity\":2},{\"name\":\"USB cable\",\"price\":4,\"quantity\":1}]"
Use read-only expressions first. Console expressions run in the live page, so assignments, DOM edits, and network calls can change the page state while debugging.
> JSON.parse(cartItems).reduce((sum, item) => sum + item.price * item.quantity, 0) 44
The successful result proves the failure came from using a JSON string as an array, not from reduce() itself.
function totalCart() { const items = Array.isArray(cartItems) ? cartItems : JSON.parse(cartItems); return items.reduce((sum, item) => sum + item.price * item.quantity, 0); }
If the page is bundled, rebuild or refresh the development server before reloading the tab.
> totalCart() 44
If a new error appears, debug that message separately instead of assuming it has the same cause.