JavaScript cheatsheet
Syntax snippets and quick notes for revision.
JS Introduction
const lesson = "JS Introduction";
const checklist = ["understand", "run", "change", "explain"];
console.log(lesson + ": " + checklist.join(" -> "));Use this js introduction pattern when a JavaScript task needs a small, readable starting point.
Variables
const lesson = "Variables";
const checklist = ["understand", "run", "change", "explain"];
console.log(lesson + ": " + checklist.join(" -> "));Use this variables pattern when a JavaScript task needs a small, readable starting point.
Data Types
const lesson = "Data Types";
const checklist = ["understand", "run", "change", "explain"];
console.log(lesson + ": " + checklist.join(" -> "));Use this data types pattern when a JavaScript task needs a small, readable starting point.
Operators
const lesson = "Operators";
const checklist = ["understand", "run", "change", "explain"];
console.log(lesson + ": " + checklist.join(" -> "));Use this operators pattern when a JavaScript task needs a small, readable starting point.
Conditions
const lesson = "Conditions";
const checklist = ["understand", "run", "change", "explain"];
console.log(lesson + ": " + checklist.join(" -> "));Use this conditions pattern when a JavaScript task needs a small, readable starting point.
Loops
const lesson = "Loops";
const checklist = ["understand", "run", "change", "explain"];
console.log(lesson + ": " + checklist.join(" -> "));Use this loops pattern when a JavaScript task needs a small, readable starting point.
Functions
const lesson = "Functions";
const checklist = ["understand", "run", "change", "explain"];
console.log(lesson + ": " + checklist.join(" -> "));Use this functions pattern when a JavaScript task needs a small, readable starting point.
Arrays
const orders = [42, 120, 18, 75]; const largeOrders = orders.filter((total) => total >= 57); console.log(largeOrders);
Use this arrays pattern when a JavaScript task needs a small, readable starting point.
Objects
const customer = { name: "Asha", plan: "Pro", active: true };
console.log(customer.name + " uses " + customer.plan);Use this objects pattern when a JavaScript task needs a small, readable starting point.
Strings
const lesson = "Strings";
const checklist = ["understand", "run", "change", "explain"];
console.log(lesson + ": " + checklist.join(" -> "));Use this strings pattern when a JavaScript task needs a small, readable starting point.
DOM
const button = document.querySelector("#save");
button?.addEventListener("click", () => {
document.body.dataset.saved = "true";
});Use this dom pattern when a JavaScript task needs a small, readable starting point.
Events
const button = document.querySelector("#save");
button?.addEventListener("click", () => {
document.body.dataset.saved = "true";
});Use this events pattern when a JavaScript task needs a small, readable starting point.