Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the skills of debugging JavaScript

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what are the skills of debugging JavaScript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Automatic breakpoint

Sometimes when the JavaScript code is executed, the code may be executed before the breakpoint is set. In fact, by writing debugger (line 8 in the code), the code execution can be automatically paused to the debugger position.

Function a () {console.log ('enter a'); b ();} function b () {console.log ('enter b'); debugger; c ();} function c () {console.log (' enter c');} a ()

two。 Manual breakpoint

Breakpoint is a very useful tool for programmers to debug code. Through breakpoint debugging, you can see the values of each variable in the current execution environment, as well as the call stack, and check the running status of the code under each step through single-step execution. As shown in the figure (Chrome debug panel-> sources-> Click the line number to add breakpoints):

3. Print the call stack

You can view the call stack of the current code through the debug panel, or you can print the function call stack through console.trace (), line 13 below.

4. Print objects in tabular form

Here is an object that can be printed through console.table (obj).

Let pkg = {"name": "mini_tools", "version": "1.0.0", "description": "", "main": "index.js", "dependencies": {"jquery": "^ 1.12.4"}, "devDependencies": {} "scripts": {"test": "echo\" Error: no test specified\ "& & exit 1"}, "author": "", "license": "ISC"} Console.table (pkg)

The print result is shown in the figure:

This is the end of the content of "what are the skills for debugging JavaScript". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report