Advanced JavaScript ES6+ Features Every Developer Should Know
August 12, 2025
164 views
4 min read
Introduction
ES6 (ECMAScript 2015) and later versions brought significant improvements to JavaScript. This guide covers the most important features every modern JavaScript developer should master.
1. Arrow Functions
Cleaner syntax for functions:
// Traditional function
function add(a, b) {
return a + b;
}
// Arrow function
const add = (a, b) => a + b;
// With single parameter
const square = x => x * x;
// With no parameters
const greeting = () => "Hello World!";
2. Template Literals
Improved string handling:
const name = "John";
const age = 30;
// Old way
const message = "Hello, my name is " + name + " and I am " + age + " years old.";
// Template literals
const message = `Hello, my name is ${name} and I am ${age} years old.`;
// Multi-line strings
const html = `
${name}
Age: ${age}
`;
3. Destructuring Assignment
Extract values from arrays and objects:
// Array destructuring
const colors = ["red", "green", "blue"];
const [primary, secondary, tertiary] = colors;
// Object destructuring
const user = {
name: "Jane",
email: "jane@example.com",
role: "admin"
};
const {name, email, role} = user;
// Nested destructuring
const response = {
data: {
users: [
{id: 1, name: "John"},
{id: 2, name: "Jane"}
]
}
};
const {data: {users}} = response;
4. Spread and Rest Operators
Powerful operators for arrays and objects:
// Spread operator
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const combined = [...arr1, ...arr2]; // [1, 2, 3, 4, 5, 6]
// Object spread
const user = {name: "John", age: 30};
const userWithEmail = {...user, email: "john@example.com"};
// Rest parameters
const sum = (...numbers) => numbers.reduce((a, b) => a + b, 0);
sum(1, 2, 3, 4, 5); // 15
5. Promises and Async/Await
Handle asynchronous operations:
// Promise
const fetchData = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("Data fetched successfully");
}, 1000);
});
};
// Using Promise
fetchData()
.then(data => console.log(data))
.catch(error => console.error(error));
// Async/Await
const getData = async () => {
try {
const data = await fetchData();
console.log(data);
} catch (error) {
console.error(error);
}
};
// Fetch API with async/await
const getUsers = async () => {
try {
const response = await fetch("/api/users");
const users = await response.json();
return users;
} catch (error) {
throw new Error("Failed to fetch users");
}
};
6. Classes
Object-oriented programming in JavaScript:
class User {
constructor(name, email) {
this.name = name;
this.email = email;
}
greet() {
return `Hello, I'm ${this.name}`;
}
static isValidEmail(email) {
return email.includes("@");
}
}
class Admin extends User {
constructor(name, email, permissions) {
super(name, email);
this.permissions = permissions;
}
hasPermission(permission) {
return this.permissions.includes(permission);
}
}
const admin = new Admin("John", "john@example.com", ["read", "write"]);
7. Modules
Organize code with import/export:
// utils.js
export const formatDate = (date) => {
return date.toISOString().split("T")[0];
};
export const capitalize = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
export default class Logger {
static log(message) {
console.log(`[${new Date().toISOString()}] ${message}`);
}
}
// main.js
import Logger, {formatDate, capitalize} from "./utils.js";
Logger.log("Application started");
const formattedDate = formatDate(new Date());
const title = capitalize("hello world");
8. Array Methods
Powerful array manipulation:
const users = [
{id: 1, name: "John", age: 30, active: true},
{id: 2, name: "Jane", age: 25, active: false},
{id: 3, name: "Bob", age: 35, active: true}
];
// map - transform array elements
const names = users.map(user => user.name);
// filter - select elements based on condition
const activeUsers = users.filter(user => user.active);
// find - get first matching element
const user = users.find(user => user.id === 2);
// reduce - accumulate values
const totalAge = users.reduce((sum, user) => sum + user.age, 0);
// some/every - test conditions
const hasActiveUsers = users.some(user => user.active);
const allAdults = users.every(user => user.age >= 18);
9. Object Enhancements
Improved object syntax:
const name = "John";
const age = 30;
// Shorthand property names
const user = {name, age}; // Instead of {name: name, age: age}
// Computed property names
const key = "email";
const user2 = {
[key]: "john@example.com",
[`is${capitalize("active")}`]: true
};
// Method shorthand
const calculator = {
add(a, b) { return a + b; }, // Instead of add: function(a, b)
multiply(a, b) { return a * b; }
};
10. Optional Chaining and Nullish Coalescing
Safe property access:
const user = {
profile: {
social: {
twitter: "@johndoe"
}
}
};
// Optional chaining
const twitter = user?.profile?.social?.twitter; // "@johndoe"
const instagram = user?.profile?.social?.instagram; // undefined
// Nullish coalescing
const displayName = user.name ?? "Anonymous";
const followers = user.followers ?? 0;
Conclusion
These ES6+ features significantly improve JavaScript development. Practice using them in your projects to write cleaner, more maintainable code.