Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>js snippetNew to Visual Studio Code? Get it now.
js snippet

js snippet

Milad Fathy

|
11,918 installs
| (0) | Free
Simple javascript Snippets to make the life easy.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

sql-snippet README

Write less, See More After selecting the snippet, switch between them with the tab key.


Css Snippet

Css Snippet

Css Snippet

Css Snippet

Conditional Statements

/* Prefix if */

if(condition) {
	
}

/* Prefix ifelse */

if(condition) {
	
}

/* Prefix elseif */

else if(condition) {
	
}

/* Prefix else */

else {
	
}

/* Prefix switch or switchcase */

switch (variable) {
	case value:
		
		break;
	default:
		
		break;
}

/* Prefix case */

case value:
	
	break;

Loop Statements

/* Prefix for */

for (let index = 0; index < 5; index++) {
	
}

/* Prefix forstate */

for(start;condition;step){
	
}

/* Prefix while */

while (condition) {
	
	step;
}

/* Prefix dowhile */

do {
	
	step;
} while (condition);

/* Prefix forin */

for (const key in object) {
	console.log(`${key}: ${object}`);
	
}

/* Prefix forof */

for (const iterator of array) {
	
}

/* Prefix foreach */

array.forEach(element => {
	
});

/* Prefix map */

array.map(element => {
	
});

Function State

/* Prefix function or func */

function name(params) {
	
}

/* Prefix arrowfunction or => */

(params) => {
	
};

class essential

/* Prefix class */

class name {
	
}

/* Prefix constructor */

constructor(params) {
	this.param = param;
	
}

/* Prefix classextends */

class name extends parent {
	constructor(params) {
		super(properties);
		this.param = param;
		
	}
}

try catch finally block

/* Prefix trycatch */

try {
	
} catch(error) {
	
}

/* Prefix trycatchfinally */

try {
	
} catch (error) {
	
} finally {
	
}

/* Prefix tryfinally */

try {
	
} finally {
	
}

A few other basic commands

/* Prefix import */

import moduleName from 'module';

/* Prefix export */

export default codeOrVars;

/* Prefix promise */

new Promise((resolve, reject) => {
	if(true){
		resolve('Yes');
	}else{
		reject('No');
	}
	resolve();
})
	.then((succ) => {
		console.log(succ);
	})
	.catch((err) => {
		console.log(err);
	});

/* Prefix ajax */

let element = document.querySelector('element').addEventListener('event', listener);
function listener(){
	const xhr = new XMLHttpRequest();
	xhr.open('Method', 'Url', async);
	xhr.onload = function () {
		if (this.status === 200) {
			
		}
	};
	xhr.send();
}

/* Prefix console or log or cl or clog */

console.log();

/* Prefix jsonstringify Or stringify or js */

JSON.stringify();

/* Prefix jsonparse Or parse or jp */

JSON.parse();

/* Prefix queryselector or qs or dqs */

document.querySelector('');

/* Prefix # */

document.querySelector('#');

/* Prefix . */

document.querySelector('.');

/* Prefix addeventlistener or ael or eventlistener */

.addEventListener('type',handler);

/* Prefix requirepackage */

const packageName = require('packageName');

/* Prefix require */

require('packageName');

In later versions, the document object, brochure object, types of events, etc. will be added and the current code snippet will be simplified.

I will be happy to try my work too

Enjoy!

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft