Back to Cheatsheets
JavaScript

ES6+ Features

Modern JavaScript syntax and features

Variables

3 items
CommandDescription
const x = 1
Block-scoped, cannot reassign
let y = 2
Block-scoped, can reassign
var z = 3
Function-scoped (avoid)

Arrow Functions

4 items
CommandDescription
const fn = () => {}
No parameters
const fn = x => x * 2
Single param, implicit return
const fn = (a, b) => a + b
Multiple params
const fn = () => ({ key: value })
Return object literal

Destructuring

5 items
CommandDescription
const { a, b } = obj
Object destructuring
const { a: renamed } = obj
Rename variable
const { a = 1 } = obj
Default value
const [x, y] = arr
Array destructuring
const [first, ...rest] = arr
Rest in array

Spread Operator

3 items
CommandDescription
[...arr1, ...arr2]
Merge arrays
{ ...obj1, ...obj2 }
Merge objects
fn(...args)
Spread as function arguments

Template Literals

3 items
CommandDescription
`Hello ${name}`
String interpolation
`Line 1\nLine 2`
Multi-line strings
tag`template`
Tagged templates

Modules

5 items
CommandDescription
export const x = 1
Named export
export default fn
Default export
import { x } from "./mod"
Named import
import fn from "./mod"
Default import
import * as mod from "./mod"
Import all