let
Block-scoped variable declaration. Can be reassigned. Prevents variable hoisting issues like var.
Browse / ES6+ JavaScript Quick Reference
ES6+ JavaScript Quick Reference
A concise cheat sheet covering key features introduced in ECMAScript starting from ES2015 (ES6) through recent versions, including syntax, examples, and tips for modern JavaScript development.
Core Syntax & Variables
let & const
|
|
|
|
|
|
|
Tip: Prefer |
|
|
Arrow Functions (`=>`)
|
Concise syntax for writing function expressions. Implicit return for single expressions. |
|
|
Lexical Arrow functions do not have their own |
|
|
Do not have |
|
|
Cannot be used as constructors with |
|
Template Literals
|
String literals allowing embedded expressions, multi-line strings, and preventing injection attacks (when used with tag functions). Syntax: use backticks ``. |
|
|
Multi-line strings without |
|
|
Tagged templates: functions applied to template literals for advanced parsing and transformation. |
|
Default Parameters
|
Allows setting default values for function parameters directly in the function signature. |
|
|
Defaults can be any expression, evaluated at call time if the parameter is missing or |
|
Data Structures & Classes
Classes
|
Syntactic sugar over JavaScript’s prototype-based inheritance. Provides a clearer way to create objects and handle inheritance. |
|
|
|
|
|
Static methods: Belong to the class itself, not instances. Use |
|
|
Getters and Setters: Define object property accessors. |
|
|
Private class fields (ES2022): Prefix property names with |
|
Destructuring (Array & Object)
|
Allows unpacking values from arrays or properties from objects into distinct variables. |
|
|
Default values during destructuring. |
|
|
Nested object destructuring. |
|
|
Array Destructuring. |
|
|
Using the rest operator with destructuring. |
|
|
Useful for function parameters. |
|
Map, Set, WeakMap, WeakSet
|
|
|
|
|
|
|
|
|
|
Only has |
|
|
Use |
|
|
Symbols
|
A primitive data type. Symbols are guaranteed to be unique. Used to create unique object property keys that won’t clash. |
|
|
Symbols are not automatically included in |
|
|
Well-Known Symbols: Built-in symbols representing internal language behaviors (e.g., |
|
Asynchronous JavaScript
Promises
|
An object representing the eventual completion (or failure) of an asynchronous operation, and its resulting value. |
|
|
States:
|
|
|
|
|
|
|
Promise Combinators:
|
|
|
|
|
|
|
|
|
|
|
Async/Await
|
Syntactic sugar on top of Promises, making asynchronous code look and behave a little more like synchronous code. |
|
|
|
|
|
|
|
|
|
Error Handling: Use |
|
|
Parallel execution: If awaiting independent promises, use |
|
Iterators and Generators
|
Iterator: An object that defines a sequence and returns values from that sequence one at a time when its Must have a |
|
|
Iterable: An object that implements the Arrays, Strings, Maps, Sets, TypedArrays are built-in iterables. Used by |
|
|
Generator function ( A function that can be paused and resumed, producing a sequence of values via the Returns a Generator object, which is an iterator. |
|
|
Pauses generator execution and returns the expression after When |
|
|
Used within a generator function to delegate to another iterable or generator. |
|
|
Passing values into a generator’s |
|
Modules & Advanced Features
Modules (Import/Export)
|
Allows organizing code into reusable modules.
|
|
|
Default exports: A module can have one default export (often a class or function). Exported with |
|
|
Importing everything from a module using Creates an object containing all exported members. |
|
|
Dynamic imports ( Returns a Promise that resolves with the module namespace object. Useful for lazy loading or conditional loading. |
|
|
Modules are executed in strict mode automatically. Variables declared in modules are scoped to the module, not the global scope. |
|
|
Spread (`...`) & Rest (`...`) Operators
|
Spread operator ( Expands an iterable (like an array or string) into individual elements. Expands an object into key-value pairs. |
|
|
Common use cases:
|
|
|
Rest parameter ( Collects all remaining elements into an array (in function parameters) or collects all remaining properties into an object (in destructuring). |
|
Optional Chaining (`?.`) & Nullish Coalescing (`??`)
|
Optional Chaining ( Provides a safe way to access nested object properties or call functions, even if intermediate properties don’t exist. Returns |
|
|
Nullish Coalescing ( Provides a default value when the left-hand side is |
|
|
Best Practices:
|
|
|
New Built-in Methods (Examples)
|
Array methods:
|
|
|
|
|
|
|
|
|
|
|
Object methods:
|
|
|
|
|
|
|
|
|
|
|
String methods:
|
|
|
|
|
|
|
|
|
|
|
|