Table of Contents
Set breakpoints to pause execution
Inspect variables and scope easily
Use the Console effectively
Home Web Front-end JS Tutorial The essential JS roundup for debugging code in Chrome DevTools

The essential JS roundup for debugging code in Chrome DevTools

Jun 29, 2025 am 12:22 AM

Chrome DevTools provides efficient JavaScript debugging methods, including setting breakpoints, checking variables, and using the console. 1. Setting breakpoints can be achieved through the Sources tag click line number or using debugger statements to help execute code line by line and track problem sources; 2. When checking variables, you can use the Scope panel to view local, closures and global variables, and observe changes in value in real time through hovering or Watch panels; 3. The console supports running any JavaScript commands, such as console.table() and dir(), and can also evaluate expressions and display error messages, thereby speeding up the debugging process.

The essential JS roundup for debugging code in Chrome DevTools

Debugging JavaScript doesn't have to be a headache. Chrome DevTools gives you all the tools you need to find and fix issues fast — if you know how to use them properly.

The essential JS roundup for debugging code in Chrome DevTools

Set breakpoints to pause execution

One of the most powerful features in DevTools is the ability to pause your code at specific lines so you can inspect variables, call stack, and more exactly when something happens.

The essential JS roundup for debugging code in Chrome DevTools

To set a breakpoint:

  • Open the Sources tab
  • Find the JavaScript file you want to debug
  • Click the line number where you want execution to pause

Once paused, you can step through the code using the buttons at the top: Step over , Step into , and Step out . This helps you follow how functions are called and where things might go wrong.

The essential JS roundup for debugging code in Chrome DevTools

A common trick: Use debugger statements in your code. When the browser hits that line during execution, it'll pause automatically — no clicking needed.

Inspect variables and scope easily

When your code is paused at a breakpoint, check the Scope panel on the right side. It shows local, closure, and global variables currently in context.

You can hover over any variable in the code editor to see its current value. This is super helpful for catching unexpected values ​​or undefined references.

If you're dealing with loops or repeated function calls, consider using the Watch panel . You can add expressions like user.id or array.length , and they'll update every time execution pauses.

Quick tip: Right-click any variable while paused and choose “Store as global variable” — this lets you access it later in the console without re-triggering the whole flow.

Use the Console effectively

The Console tab is more than just for console.log() . You can run arbitrary JavaScript here anytime — even when not debugging.

Some useful console commands:

  • console.table() – for nicely formatted tables from arrays or objects
  • dir(object) – to get a full list of properties and methods of an object
  • $0 – refer to the currently selected DOM element in Elements tab

While debugging, you can also evaluate expressions directly in the console. For example, if you're paused inside a function and want to test what myFunction(input) returns, just type it into the console and see.

Don't forget that the console shows errors and warnings too. A red error icon usually tells you where something went wrong before you even start stepping through code.


That's the core toolkit for everyday JS debugging in Chrome. These techniques work whether you're working on a small script or a complex app. The key is combining visual inspection with smart pausing and quick evaluation.

The above is the detailed content of The essential JS roundup for debugging code in Chrome DevTools. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vercel SPA routing and resource loading: Solve deep URL access issues Vercel SPA routing and resource loading: Solve deep URL access issues Aug 13, 2025 am 10:18 AM

This article aims to solve the problem of deep URL refresh or direct access causing page resource loading failure when deploying single page applications (SPAs) on Vercel. The core is to understand the difference between Vercel's routing rewriting mechanism and browser parsing relative paths. By configuring vercel.json to redirect all paths to index.html, and correct the reference method of static resources in HTML, change the relative path to absolute path, ensuring that the application can correctly load all resources under any URL.

Vercel Single Page Application (SPA) Deployment Guide: Solving Deep URL Asset Loading Issues Vercel Single Page Application (SPA) Deployment Guide: Solving Deep URL Asset Loading Issues Aug 13, 2025 pm 01:03 PM

This tutorial aims to solve the problem of loading assets (CSS, JS, images, etc.) when accessing multi-level URLs (such as /projects/home) when deploying single page applications (SPAs) on Vercel. The core lies in understanding the difference between Vercel's routing rewriting mechanism and relative/absolute paths in HTML. By correctly configuring vercel.json, ensure that all non-file requests are redirected to index.html and correcting asset references in HTML as absolute paths, thereby achieving stable operation of SPA at any depth URL.

js add element to start of array js add element to start of array Aug 14, 2025 am 11:51 AM

In JavaScript, the most common method to add elements to the beginning of an array is to use the unshift() method; 1. Using unshift() will directly modify the original array, you can add one or more elements to return the new length of the added array; 2. If you do not want to modify the original array, it is recommended to use the extension operator (such as [newElement,...arr]) to create a new array; 3. You can also use the concat() method to combine the new element array with the original number, return the new array without changing the original array; in summary, use unshift() when modifying the original array, and recommend the extension operator when keeping the original array unchanged.

Qwik: A Resumable Framework for Instant-Loading Web Apps Qwik: A Resumable Framework for Instant-Loading Web Apps Aug 15, 2025 am 08:25 AM

Qwikachievesinstantloadingbydefaultthroughresumability,nothydration:1)TheserverrendersHTMLwithserializedstateandpre-mappedeventlisteners;2)Norehydrationisneeded,enablingimmediateinteractivity;3)JavaScriptloadson-demand,onlywhenuserinteractionoccurs;4

How to lazy load images with JavaScript How to lazy load images with JavaScript Aug 14, 2025 pm 06:43 PM

Usetheloading="lazy"attributefornativelazyloadinginmodernbrowserswithoutJavaScript.2.Formorecontrolorolderbrowsersupport,implementlazyloadingwiththeIntersectionObserverAPIbysettingdata-srcfortheactualimageURLandusingaplaceholderinsrc.3.Obse

In-depth analysis of common vulnerabilities and improvement strategies for JavaScript XSS defense functions In-depth analysis of common vulnerabilities and improvement strategies for JavaScript XSS defense functions Aug 14, 2025 pm 10:06 PM

This article explores in-depth security vulnerabilities in custom JavaScript XSS defense functions, especially incomplete character escape and easy bypass to keyword-based filtering. By analyzing an example function, it reveals the risks of unprocessed keyword characters such as quotes and backquotes, and how code obfuscation techniques circumvent simple keyword detection. The article emphasizes the importance of context-sensitive escape and recommends the adoption of mature libraries and multi-layer defense strategies to build more robust security protection.

How to access and modify HTML elements using the DOM in JavaScript How to access and modify HTML elements using the DOM in JavaScript Aug 16, 2025 am 11:25 AM

ToaccessandmodifyHTMLelementsusingJavaScript,firstselecttheelementusingmethodslikedocument.getElementById,document.querySelector,ordocument.querySelectorAll,thenalteritscontent,attributes,orstyles;forexample,useelement.textContentforsafetextupdates,e

JavaScript multi-condition filtering: implement dynamic product filtering based on AND/OR logic JavaScript multi-condition filtering: implement dynamic product filtering based on AND/OR logic Aug 22, 2025 am 10:00 AM

This tutorial introduces in detail how to use JavaScript to implement multi-condition dynamic filtering function, allowing users to filter products based on multiple attributes such as color and size. Through clear HTML structure and JavaScript code examples, the article demonstrates how to flexibly handle AND and OR logic to meet complex user filtering needs and provides optimization suggestions.

See all articles