JavaScript Cheat Sheet

Search fast JavaScript reminders for variables, arrays, async flows, modules, objects, JSON, and everyday syntax patterns.

Last updated: August 2026 | By Workshelve Team

Variables

const name = 'Workshelve';
let count = 0;

Use const by default and let when reassignment is required.

Functions

function greet(name) {
  return `Hello, ${name}`;
}

Function declarations are hoisted and work well for named reusable logic.

Arrow functions

const double = (value) => value * 2;

Arrow functions are concise and keep lexical this binding.

Arrays

const tools = ['Base64', 'JSON', 'YAML'];
const upper = tools.map((item) => item.toUpperCase());

Use map, filter, and reduce for data transformation.

Objects

const tool = { id: 'json-parser', active: true };
const { id, active } = tool;

Destructuring makes object access shorter and clearer.

Optional chaining

const city = user?.profile?.address?.city ?? 'Unknown';

Optional chaining prevents crashes when intermediate values are missing.

Async await

async function loadTools() {
  const response = await fetch('/api/tools');
  const data = await response.json();
  return data;
}

Use async/await inside an async function, or at top level in a JavaScript module, to write asynchronous code in a readable sequence.

Promises

fetch('/api/tools')
  .then((response) => response.json())
  .then((data) => console.log(data));

Promise chains are still useful when composing async steps directly.

Template literals

const message = `Loaded ${count} tools.`;

Template literals support interpolation and multiline strings.

Modules

export function formatName(value) {
  return value.trim();
}

import { formatName } from './format';

Use named exports for reusable utilities and explicit imports.

JSON

const text = JSON.stringify(payload, null, 2);
const parsed = JSON.parse(text);

Stringify serializes structured data; parse restores it.

Sets and maps

const ids = new Set(['a', 'b']);
const lookup = new Map([['json', 'ready']]);

Sets help with uniqueness; Maps help with keyed lookups.

Modern syntax first

The sheet focuses on current JavaScript patterns like destructuring, optional chaining, and async/await.

Small examples on purpose

Each block is designed to be easy to scan and copy into real work without extra boilerplate.

Use it like a memory jog

This works best as a quick refresher when you remember the idea but want the exact shape of the syntax.

Related Tools