JavaScript Cheatsheet - ES6+ Command Reference

All the JavaScript ES6+ syntax you need for daily development — from basics to async/await, organized by category, ready to copy into your code.

Languages·43 commands·Last updated 2026-07-21
Back to Languages

Variables & Functions 6

const name = "value"
Declare constant, cannot be reassigned
let count = 0
Declare block-scoped variable
const fn = (x) => x * 2
Arrow function, single-line omits return
const fn = (x, y = 1) => {}
Default parameters
const fn = (...args) => {}
Rest parameters, collects all args into array
function* generator() { yield 1; }
Generator function

Destructuring 5

const [a, b] = [1, 2]
Array destructuring
const { name, age } = person
Object destructuring
const { name: userName } = person
Destructuring with rename
const [first, ...rest] = arr
Rest elements
function fn({ name, age = 18 }) {}
Function parameter destructuring

String & Template 6

`Hello ${name}`
Template literal with interpolation
str.includes("text")
Check if string contains substring
str.startsWith("prefix")
Check if string starts with prefix
str.endsWith("suffix")
Check if string ends with suffix
str.padStart(10, "0")
Pad start to specified length
str.trim() / trimStart() / trimEnd()
Remove whitespace

Array Methods 8

arr.map(x => x * 2)
Map each element, returns new array
arr.filter(x => x > 0)
Filter elements, returns new array
arr.reduce((acc, x) => acc + x, 0)
Reduce to a single value
arr.find(x => x.id === 1)
Find first matching element
arr.findIndex(x => x > 0)
Find first matching index
arr.some(x => x > 0) / every(x => x > 0)
Check if any / all match condition
arr.flat() / flatMap()
Flatten array
Array.from(iterable) / Array.of(1,2,3)
Create arrays

Async/Await 6

const p = new Promise((resolve, reject) => {})
Create a Promise
p.then(res => {}).catch(err => {})
Chaining
async function fn() { await p; }
async/await syntax
Promise.all([p1, p2])
Run in parallel, all must succeed
Promise.race([p1, p2])
Return the first settled
Promise.allSettled([p1, p2])
Wait for all, regardless of outcome

Modules 6

import { name } from "./module.js"
Named import
import * as utils from "./utils.js"
Import all as namespace
import defaultExport from "./module.js"
Default import
export const name = "value"
Named export
export default function() {}
Default export
export { name, age }
Export multiple

Object & Class 6

const obj = { name, age }
Property shorthand
const obj = { fn() {} }
Method shorthand
const obj = { [`key${i}`]: value }
Computed property names
Object.keys(obj) / values(obj) / entries(obj)
Get keys/values/entries
class MyClass { constructor() {} }
Class definition
class Child extends Parent {}
Class inheritance

💡 Tips

  • Prefer const; only use let when reassignment is needed. Avoid var entirely.
  • Arrow functions don't have their own this — they capture the surrounding context. Not suitable for object methods.
  • async/await is syntactic sugar over Promises, making async code read like synchronous code.