What were the biggest changes introduced by ES6, also known as ES2015?
ES2015 was the largest single revision of the language, and it is the release that most people mean when they say ES6. The headline changes were block-scoped declarations, arrow functions, classes, template literals, destructuring, default and rest parameters, the spread syntax, modules with import and export, the new Map and Set collections, Symbol, generators, Promises, and the for...of loop.
// The older ES5 style.
var greetOld = function (name) {
return 'Hi ' + name;
};
// The ES2015 style.
const greet = function (name = 'there') {
return 'Hi ' + name;
};
console.log(greetOld('Ada')); // Hi Ada
console.log(greet()); // Hi there
console.log(greet('Bob')); // Hi BobTwo big ideas sit underneath most of those changes. The first one is that the language stopped treating functions as the only way to build reusable behaviour. Arrow functions made callbacks shorter, and classes gave object-oriented programmers a syntax they already knew. The second one is that moving data around became a first class job. Destructuring and spread let you pull values out of objects and arrays and put them back together, and that replaced a lot of index arithmetic and manual copying.
The later editions kept going in the same direction instead of replacing what came before. ES2018 added async iteration and object rest and spread. ES2020 added optional chaining and nullish coalescing. ES2021 added logical assignment operators. ES2022 added class fields and the at method on arrays. ES2023 added array methods such as findLast and toSorted. The theme is steady. There is less boilerplate, missing values are handled more safely, and working with collections feels more comfortable.