Last Updated : 05 Aug, 2025
ES6, or ECMAScript 2015, is the 6th version of the ECMAScript programming language. ECMAScript is the standardization of JavaScript, which was released in 2015 and subsequently renamed as ECMAScript 2015.
New Features in ES6 1. The let KeywordThe let variables are mutable, i.e., their values can be changed. It works similarly to the var keyword with some key differences, like scoping, which makes it a better option when compared to var.
JavaScript
let n = 10;
{
let n = 2; // Block-scoped variable
console.log(n);
}
console.log(n);
It prevents variable leakage outside of the intended scope.
2. The const Keywordconst is used to declare variables with a constant value, ensuring the value cannot be reassigned.
JavaScript
const PI = 3.14159;
PI = 3; // Error: Assignment to constant variable
Ideal for declaring configuration constants or fixed values.
3. Arrow FunctionsArrow functions provide a concise syntax for writing function expressions and automatically bind this to the surrounding context.
JavaScript
// Traditional function
function add(a, b) { return a + b; }
// Arrow function
const add = (a, b) => a + b;
Destructing in JavaScript basically means the breaking down of a complex structure(Objects or arrays) into simpler parts
Object Destructuring
JavaScript
const obj = {
name : "Raj",
age : 25
};
const {name, age} = obj;
console.log(name, age);
Array Destructuring
JavaScript
const a = [ "red", "blue", "green" ];
const [first, second] = a;
console.log(first, second);
5. The Spread (...) Operator
The spread operator expands an array or object into individual elements or properties.
JavaScript
const n1 = [ 1, 2, 3 ];
const n2 = [...n1, 4, 5 ];
console.log(n2);
6. The For/Of Loop
The for/of loop allows you to iterate over iterable objects like arrays, strings, Maps, and Sets but in a short syntax as compared to other loops.
Iterating Over an Array
JavaScript
const a = [ "apple", "banana", "cherry" ];
for (const fruit of a) {
console.log(fruit);
}
apple banana cherry
Iterating Over a String
JavaScript
const s = "hello";
for (const char of s) {
console.log(char);
}
7. Maps and Sets
Map: Maps store key-value pairs where keys can be any data type.
JavaScript
const map = new Map();
map.set("a", 1);
map.set("b", 2);
console.log(map.get("a"));
Set: Sets store unique values of any type.
JavaScript
const set = new Set([ 1, 2, 3, 3 ]);
console.log(set);
Set(3) { 1, 2, 3 }8. Classes
ES6 introduced classes in JavaScript. Classes in javascript can be used to create new Objects with the help of a constructor, each class can only have one constructor inside it.
JavaScript
class Animal {
speak() { console.log("The animal makes a sound"); }
}
const dog = new Animal();
dog.speak();
The animal makes a sound
Promises simplify handling asynchronous operations by providing .then and .catch methods.
JavaScript
const fetch = () => {
return new Promise((resolve, reject) => {
setTimeout(() => resolve("Data fetched"), 2000);
});
};
fetch().then(data => console.log(data));
10. Default Parameters
Allows functions to have default values for parameters.
JavaScript
function greet(name = "Guest") { return `Hello, ${name}!`; }
console.log(greet());
Additional Enhancements
ES6 is fully supported in all modern browsers since June 2017:
Chrome
51
Edge
15
Firefox
54
Safari
10
Opera
38
May 2016
Apr 2017
Jun 2017
Sep 2016
Jun 2016
Note: ES6 is not supported in Internet Explorer.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4