Show Menu
Cheatography

Modern JavaScript Cheat Sheet (DRAFT) by

A basic JavaScript cheat sheet utilizing ES6 keywords

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Comments

// Inline comment (single line)
// For single line thoughts & URLs
 
/*
Block comment (multi­-line)
This type of comment spans multiple lines
*/
 
/**
* @desc JSdoc comment
* @desc For creating HTML code docs
* @desc See:  http:/­/us­ejs­doc.org for details
*/
 

Functi­ons­/Me­tho­ds/­Sub­rou­tines

function doStuf­f(p­aram1, param2) {
 ­ ­ ­ ­return param1 + param2;
}
 
let value = doStuf­f(10, 8); //value will be 18
fu­nctions are mini-p­­ro­grams inside your global pr­ogram. Code in here is scoped locally from from the opening curly brace to the closing curly brace. The return keyword can be used to return a value to the caller.
 

Variables, Constants, & Data Types

let lastName; //globally declared variable
const PI = 3.14; //declared & initia­lized const
let age = 10; local number variable
let animalType = 'dog'; string variable
let isValid = true; boolean variable
Variables are declared with the let keyword. Constants are declared with the const keyword. They are both initia­lized with the = symbol. Global­ly-­scoped variables should be declared only, then initia­lized with a mutator method. Locall­y-s­coped variables should be declared & initia­lized on the same line. Constants are immutable & variables are mutable.