JavaScript ES6 Features
Hey there! If you’re learning JavaScript, ES6 (ECMAScript 2015) introduced some powerful features that make your code cleaner, shorter, and easier to read. Let’s explore them step by step.
1. Variables and Functions
With ES6, we use let and const instead of var for better scope control.
const name = "John";// Traditional function
function sum(x, y) {
return x + y;
}// Arrow function (ES6)
const sumArrow = (x, y) => x + y;
👉 Arrow functions make code shorter and more readable.
2. Object & Array Destructuring
Destructuring allows you to extract values easily from objects and iterables (like arrays or strings).
const user = { name: "John", age: 20 };
const { name, age } = user;const address = ["Kathmandu", "Bagmati"];
const [city, province] = address;👉 This works with any iterable, not just arrays.
3. Array Methods + ES6 Power
JavaScript already had powerful array methods like map, filter, and sort (introduced before ES6).
But ES6 makes them more powerful and cleaner with arrow functions.
const numbers = [1, 2, 3, 4, 5];const doubled = numbers.map(n => n * 2);Get AakritiCodes’s stories in your inbox
Join Medium for free to get updates from this writer.
const even = numbers.filter(n => n % 2 === 0);
const sorted = numbers.sort((a, b) => b - a);
👉 ES6 didn’t introduce these methods, but made them easier to use.
4. Template Literals
No more messy string concatenation with +.
const sentence = `Hello! My name is ${name} and I am ${age} years old.
I live in ${city}, District ${province} Province.`;👉 Cleaner, readable, and supports multi-line strings.
5. Spread Operator
The spread operator (...) helps copy or merge arrays and objects easily.
const arr1 = [1, 2];
const arr2 = [...arr1, 3, 4];const userCopy = { ...user, country: "Nepal" };👉 Very useful for immutability and modern development.
Final Thoughts
Using ES6 features, your JavaScript code becomes:
- Cleaner
- Shorter
- Easier to maintain
ES6 is not just about new features — it’s about writing better JavaScript.







