The essential JS roundup for debugging code in Chrome DevTools
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.
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.

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.

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.

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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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.

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.

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.

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

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

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.

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

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.
