5 JavaScript ES6 Features Every Web Developer Should Know
By Tom · Last reviewed · 2 minute read
The five ES6 features that make the biggest day-to-day difference are arrow functions, template literals, destructuring, the spread and rest operators, and let and const. Together they make JavaScript shorter, easier to read and less prone to bugs.
On this page
JavaScript ES6 (ECMAScript 2015) changed how most JavaScript is written. Here are five of its features that make code shorter and easier to read.
1. Arrow Functions
Arrow functions provide a concise syntax for writing function expressions. They automatically bind the current scope, eliminating common this context issues.
// Traditional function
function add(a, b) {
return a + b;
}
// Arrow function
const add = (a, b) => a + b;
// Real-world example: Array methods
const numbers = [1, 2, 3, 4];
const doubled = numbers.map(num => num * 2);
2. Template Literals
Template literals make string interpolation and multiline strings much easier to write and read.
const user = {
name: 'John',
role: 'Developer'
};
// Old way
const message = 'Hello ' + user.name + ', you are a ' + user.role;
// Template literal way
const betterMessage = `Hello ${user.name}, you are a ${user.role}`;
// Multiline example
const html = `
<div class="user-card">
<h2>${user.name}</h2>
<p>${user.role}</p>
</div>
`;
3. Destructuring Assignment
Destructuring lets you extract values from objects and arrays efficiently, reducing boilerplate code.
// Object destructuring
const project = {
title: 'Portfolio',
client: 'ABC Corp',
tech: ['React', 'Node']
};
const { title, client } = project;
// Array destructuring
const [firstTech, secondTech] = project.tech;
4. Spread/Rest Operators
These operators simplify working with arrays and objects, making it easier to combine and extract data.
// Spread operator
const baseConfig = {
api: 'https://api.example.com',
timeout: 5000
};
const developmentConfig = {
...baseConfig,
debug: true
};
// Rest parameter
const sum = (...numbers) => numbers.reduce((total, num) => total + num, 0);
console.log(sum(1, 2, 3, 4)); // Output: 10
5. Let and Const Declarations
Block-scoped variables provide better control over variable scope and mutability.
// Block scope example
if (true) {
let blockScoped = 'Only available inside this block';
const CONSTANT = 'Cannot be reassigned';
}
// Array manipulation example
const numbers = [1, 2, 3];
numbers.push(4); // Valid - array content can change
// numbers = [5, 6, 7]; // Invalid - cannot reassign const
Why These Features Matter
Most modern JavaScript uses these ES6 features. They make code shorter, help prevent common bugs and make it easier to maintain, on small websites and large web apps alike.
Try using them in your next project.
