Home Web Front-end JS Tutorial How to debug using Console

How to debug using Console

May 08, 2018 pm 03:42 PM
console debug how

This time I will show you how to debug using Console, and what are the precautions for using Console to debug. The following is a practical case, let’s take a look.

Preface

Over the past ten years, one of my biggest passions has been front-end development (especially

JavaScript). As a "craftsman", I like to specialize in various tools. In this article, I will introduce you to some debugging techniques using the old-fashioned console.

Yes, we all know the following basic skills:

console.log(‘Hello World!');
console.info(‘Something happened…'); 
console.warn(‘Something strange happened…'); 
console.error(‘Something horrible happened…');
Copy after login
From now on, I will teach you some skills you don’t know and let you become an experienced driver!

1. console.trace()

If you want to know where the message is printed, use

console.trace( ) to get the stacktrace of the data to be printed.

2. console.time() && console.timeEnd()

If you want to analyze For function performance, you can use

console.time() to time and console.timeEnd() to end the time. The console will print out the time difference between the two times.

3. console.memory

If you find performance issues difficult to analyze, you may also To consider whether there is a memory leak, you can use

console.memory (note that memory is a property of the console, not a function) to check the current heap usage.

4. console.profile('profileName') & console.profileEnd('profileName')

Although not a standard approach, it is widely accepted and used. You can use these two commands to start and stop profiling. This helps you do accurate profiling in your code. Rather than relying on manual mouse clicks. You can find the profile just now in the browser console JavaScript Profiler.

5. console.count(“STUFF I COUNT”)

Sometimes in order to record a How many times a function or a piece of code has been executed repeatedly can be recorded using

console.count('?'). Every time this code is executed, it will automatically increase by 1.

6. console.assert(false, “Log me!”)

You can use

console.assertTo output messages under certain false conditions instead of using if-else.

Note: will report an error (Assertion Error) under Node.js.

7. console.group('group') & console.groupEnd('group')

If you want to format the printed log, you can use

console.group() and console.groupEnd() . Use console.group to aggregate logs into groups and form nested hierarchies.

Please see the example:

8. String substitutions

You can use console.log to print variables(%s = string, %i = <a href="http://www.php.cn/wiki/54.html" target="_blank">integer</a>, %o = <a href="http://www.php.cn/wiki/60.html" target="_blank">object</a>, %f = float).

9. console.clear()

We have output a lot of records on the console, Use console.clear() to clear it.

10. console.table()

The last one! You can use console.table() to print the object in table form.

# I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps to globally introduce bass.scss into Vue

node custom command line tool

The above is the detailed content of How to debug using Console. 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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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)

Pre-orders open for new Nintendo Switch Lite refresh Pre-orders open for new Nintendo Switch Lite refresh Jun 29, 2024 am 06:49 AM

Nintendo has opened pre-orders for the latest version of the Switch Lite (curr. $189.99 on Amazon). However, the device is not available to order globally just yet. To recap, the company presented the Switch Lite Hyrule Edition almost two weeks ago d

What does console mean? What does console mean? Sep 05, 2023 pm 02:43 PM

Console means console. It is a device or software that interacts with a computer system. It is usually a device with a keyboard and a screen for inputting and outputting information. The console was originally Used for large computer systems, and later also applied to personal computers and servers, it can help users manage and maintain computer systems, as well as install operating systems and applications, debug programs, etc.

Clear console output using Console.Clear function in C# Clear console output using Console.Clear function in C# Nov 18, 2023 am 11:00 AM

Use the Console.Clear function in C# to clear the console output. In C# console applications, we often need to clear the output information in the console in order to display new content or provide a better user experience. C# provides the Console.Clear function to implement this function, which can clear the output in the console and make the interface blank again. The calling format of the Console.Clear function is as follows: Console.Clear(); This function does not require any input

How to solve the problem of invalid debugging when setting breakpoints in SpringBoot project How to solve the problem of invalid debugging when setting breakpoints in SpringBoot project May 11, 2023 am 10:49 AM

I am new to the springboot project. (1) I found that breakpoint debugging was ineffective. I was very depressed and searched for solutions online. All I saw were some very complicated solutions, which were said to be remote debugging, but also required additional opening slogans. This is different from a traditional project, so I don’t think it’s necessary. So after some exploration, I found that there is a simpler way. The steps are as follows: Add a configuration in the plugin part of the pom file: false and it will be ok; (2) Regarding the error in the SpringBoot project that the web.xml file is missing, because Traditional web projects require web.xml files, but SpringBoot projects do not require web.xml files.

Nintendo announces new Switch Lite refresh before Switch 2 release Nintendo announces new Switch Lite refresh before Switch 2 release Jun 20, 2024 am 09:41 AM

Nintendo presented plenty of games yesterday during its most recent Nintendo Direct event, an overview of which we have provided separately. Additionally, the company also announced a new version of the Switch Lite (curr. $194.93 on Amazon), possibly

MagicX XU Mini M: Teardown reveals RK3326 CPU instead of advertised RK3562, MagicX severs ties with 3rd-party dev MagicX XU Mini M: Teardown reveals RK3326 CPU instead of advertised RK3562, MagicX severs ties with 3rd-party dev Sep 01, 2024 am 06:30 AM

If you purchased the MagicX XU Mini M recently, this news might come as a surprise. A hardware and software teardown of the newly released handheld console revealed that the advertised RK3562 CPU is, in fact, a lower-specced, older RK3326 processor.

what does console mean what does console mean Aug 09, 2023 pm 04:21 PM

A console is a console, an interactive interface used in computer programs to input and output text or commands. In different operating systems and development environments, the console may have different appearances and functions. Usually a text interface that provides a command line interface or command line prompt, allowing the user to enter commands through the keyboard and display the output of the program.

Nintendo Switch 2 rumored to get ports of Assassin\'s Creed Shadows and previous entries in the series Nintendo Switch 2 rumored to get ports of Assassin\'s Creed Shadows and previous entries in the series Aug 14, 2024 pm 12:36 PM

Last week, Paul Gele, a known gaming insider, shared that the upcoming Nintendo Switch 2 will get major third-party AAA ports at launch. This is something to look forward to because the first-gen gaming handheld didn't get any AAA titles at launch. B

See all articles