Detailed explanation of two quick ways to write console.log in vscode

Detailed explanation of two quick ways to write console.log in vscode

(I) Method 1: Define it in advance directly in the script tag, only applicable to this HTML file!

 let add = function(a,b){
 	return a + b;
 };
 console.log(add(20,300));
 
 const { ['log']:C } = console;
 C(add(20,300));

(ii) Method 2: Press the tab key to quickly generate console.log, and the cursor is inside (). Press the tab key again and the cursor will automatically jump to the next line!
1. Open the vscode editor, select File -> Preferences -> User Snippets, enter javascript.json and press enter.
When we use it for the first time, we will find a commented code as follows:

{
	// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. The prefix is ​​what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
	// same ids are connected.
	// Example:
	// "Print to console": {
	// "prefix": "log",
	// "body": [
	// "console.log('$1');",
	// "$2"
	// ],
	// "description": "Log output to console"
	// }
}

2. The following interval codes are used to release Example. The meanings of some parameters are as follows:
①prefix: The entry for code shortcut keys. Here we can set it according to personal habits. For example, if I set cl, then I can directly generate console.log with the tab key;
②body represents the main body of the code:
$1 indicates the position where the cursor first appears after the code is generated quickly
$2 is written below "console.log('$1');", which means that after the quick generation of console.log(), a line will be left after the code, and when the tab key is pressed again, the cursor will jump to $2 (the left line).

{
	// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. The prefix is ​​what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
	// same ids are connected.
	// Example:
	"Print to console": {
		"prefix": "cl",
		"body": [
			"console.log('$1');",
			"$2"
		],
		"description": "Log output to console"
	}
}

This is the end of this article about two quick ways to write console.log in vscode. For more relevant vscode console.log writing content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vscode common shortcut key list, plug-in installation, console.log detailed explanation

<<:  The use of FrameLayout in six layouts

>>:  DOCTYPE element detailed explanation complete version

Recommend

Linux ssh server configuration code example

Use the following terminal command to install the...

MySql index improves query speed common methods code examples

Use indexes to speed up queries 1. Introduction I...

Nginx solves cross-domain issues and embeds third-party pages

Table of contents Preface difficulty Cross-domain...

How to customize more beautiful link prompt effect with CSS

Suggestion: Handwriting code as much as possible c...

WeChat applet implements SMS login in action

Table of contents 1. Interface effect preview 2.u...

Implementing form submission without refreshing the page based on HTML

Using ajax to implement form submission without re...

Detailed Analysis of the Selection of MySQL Common Index and Unique Index

Suppose a user management system where each perso...

The latest popular script Autojs source code sharing

Today I will share with you a source code contain...

A brief introduction to React

Table of contents 1. CDN introduction 1.1 react (...

The process of installing Docker in Linux system

In this blog, I will walk you through the process...

HTML+CSS to achieve drop-down menu

1. Drop-down list example The code is as follows:...

Summary of learning Docker commands in one article

Table of contents Introduction Mirror repository ...

Vue implements Modal component based on Teleport

Table of contents 1. Get to know Teleport 2. Basi...

Linux /etc/network/interfaces configuration interface method

The /etc/network/interfaces file in Linux is used...

Detailed explanation of the basic usage of the img image tag in HTML/XHTML

The image tag is used to display an image in a we...