ES6+ Cheat Sheet
This lesson explains ES6+ Cheat Sheet with clear examples, use cases, and best practices so you can use modern JavaScript confidently in real projects.
ES6 Cheat Sheet
This ES6 Cheat Sheet provides a quick reference for the most commonly used modern JavaScript features. It is organized by category and is ideal for interviews, daily development, React, Node.js, frontend applications, and coding assessments.
1. Variables
- Declare constant
const PI = 3.14; - Declare variable
let count = 0; - Avoid using var
var oldWay = true;
2. Template Literals
- String interpolation
const name = "John"; const message = `Hello ${name}`; - Multi-line string
const text = `First Line Second Line`;
3. Arrow Functions
- Simple function
const add = (a, b) => a + b; - Multiple statements
const multiply = (a, b) => { return a * b; }; - No parameters
const greet = () => "Hello";
4. Default Parameters
function greet(name = "Guest") {
return `Hello ${name}`;
} 5. Object Destructuring
const user =
{
name: "Alice",
age: 25
};
const {
name,
age
} = user; 6. Array Destructuring
const colors =
["Red", "Green", "Blue"];
const
[
first,
second
] = colors; 7. Spread Operator
- Copy Array
const copy = [...items]; - Merge Arrays
const merged = [...a, ...b]; - Copy Object
const clone = { ...user }; - Update Object
const updated = { ...user, age: 30 };
8. Rest Parameters
function sum(...numbers) {
return numbers.reduce(
(total, num) =>
total + num,
0
);
} 9. Object Shorthand
const name = "John";
const age = 25;
const user =
{
name,
age
}; 10. Object Methods
const calculator =
{
add(a, b) {
return a + b;
}
}; 11. Important Array Methods
-
Transforms every item.array.map() -
Returns matching items.array.filter() -
Returns first match.array.find() -
Produces a single value.array.reduce() -
Returns true if one matches.array.some() -
Returns true if all match.array.every() -
Checks whether a value exists.array.includes() -
Flattens nested arrays.array.flat() -
Maps and flattens.array.flatMap()
12. Classes
class User {
constructor(name) {
this.name = name;
}
greet() {
return "Hello";
}
} 13. Inheritance
class Admin extends User {
deleteUser() {
console.log("Deleted");
}
} 14. ES Modules
-
export default User; -
export const PI = 3.14; -
import User from "./User.js"; -
import { PI } from "./math.js";
15. Promise
fetch(url)
.then(response =>
response.json())
.catch(error =>
console.error(error)); 16. Async Await
async function loadUsers() {
const response =
await fetch(url);
return response.json();
} 17. Iteration
for (const item of items) {
console.log(item);
} for await
(const chunk of stream) {
console.log(chunk);
} 18. Collections
Map
const map =
new Map();
map.set("A", 1); Set
const unique =
new Set(
[1, 2, 2, 3]
); 19. Symbol
const id =
Symbol("id"); 20. BigInt
const value =
12345678901234567890n; 21. Optional Chaining
const city =
user?.address?.city; 22. Nullish Coalescing
const pageSize =
settings.pageSize ?? 20; 23. Strict Comparison
value === 100
value !== 0 24. Useful Loops
for...of
Iterate values.
for...in
Iterate object keys.
25. Useful String Methods
text.includes() text.startsWith() text.endsWith() text.repeat() text.padStart() text.padEnd() text.trim() 26. Useful Number Methods
Number.isNaN() Number.isInteger() Number.parseInt() Number.parseFloat() 27. Useful Object Methods
Object.keys() Object.values() Object.entries() Object.assign() Object.freeze() 28. ES6 Best Practices
- Prefer
constoverlet. - Avoid
var. - Use template literals.
- Prefer destructuring.
- Use spread instead of manual copying.
- Keep functions small.
- Use modules instead of global variables.
- Use async/await instead of nested callbacks.
- Prefer immutable updates.
- Always use strict equality.
29. Interview Favorites
- let vs const vs var
- Arrow functions vs regular functions
- this keyword
- Closures
- Promises
- Async Await
- Destructuring
- Spread vs Rest
- Modules
- Map vs Object
- Set vs Array
- BigInt
- Optional chaining
- Template literals
30. ES6 Quick Summary
- Variables →
let,const - Functions → Arrow Functions
- Strings → Template Literals
- Objects → Destructuring, Spread
- Arrays → Map, Filter, Reduce
- Modules → Import, Export
- Classes → OOP Support
- Async → Promise, Async/Await
- Collections → Map, Set
- New Types → Symbol, BigInt
- Safer Access → Optional Chaining
- Better Defaults → Nullish Coalescing
Interview Tip
Memorize this cheat sheet by category instead of individual syntax. Interviewers often ask questions grouped around variables, functions, arrays, objects, asynchronous programming, modules, and collections rather than isolated ES6 features.