ES2015 (ES6): The Big Update

Updated · 7 min read
mediumES2026javascriptes2015es6features

ES2015, widely called ES6, was the largest update in JavaScript's history: six years in the making, it added more features than all previous editions combined and turned JavaScript into the language most people write today. This lesson is a tour, grouped by purpose: for each feature, a short example and the course lesson that teaches it in depth. Use it to recognize the modern style, and as a checklist when updating older code.

In One Minute

  • Variables and scope: let, const, block scope.
  • Functions: arrow functions, default and rest parameters, spread.
  • Syntax: template literals, destructuring, shorthand and computed properties, for...of.
  • Classes and modules: class, extends, super, import/export.
  • Built-ins: promises, Map, Set, WeakMap, WeakSet, symbols, iterators and generators, Proxy, Reflect, new string, number, array and object methods.

Variables and Scope

let-const.js▶ Try it
const rate = 2;
let total = 0;
for (let day = 1; day <= 3; day++) total += rate;
console.log(total, typeof day);
Output
6 undefined

const for values that aren't reassigned, let for those that are, both block-scoped, ending the era of var hoisting surprises. See "Variables: Let and Const" and "Var, Let and Const Compared".

Functions

functions.js▶ Try it
const lateFee = (days, rate = 2, ...extra) => Math.min(days * rate, 30) + extra.length;
console.log(lateFee(5), lateFee(20, 3), lateFee(1, 2, "a", "b"));
 
const fees = [120, 85, 45];
console.log(Math.max(...fees), [...fees, 200]);
Output
10 30 4
120 [120, 85, 45, 200]
FeatureLesson
Arrow functions (and lexical this)"Arrow Functions"
Default parameters, rest parameters"Parameters and Arguments"
Spread in calls and arrays"Destructuring and Spread"

Syntax Conveniences

syntax.js▶ Try it
const name = "Srihitha";
const grade = 11;
const field = "balance";
 
const student = { name, grade, [field]: 85, describe() { return `${this.name}, grade ${this.grade}`; } };
const { balance, ...rest } = student;
const [first, , third] = ["Navika", "Srihitha", "Advitha"];
 
console.log(student.describe(), balance, Object.keys(rest));
console.log(first, third);
for (const letter of "Fee") console.log(letter);
Output
Srihitha, grade 11 85 ['name', 'grade', 'describe']
Navika Advitha
F
e
e
FeatureLesson
Template literals (and tagged templates)"Template Literals"
Destructuring"Destructuring and Spread"
Shorthand properties, computed keys, method shorthand"Objects", "Object Methods and This"
for...of"The for...of and for...in Loops"

(Object rest and spread, { ...rest }, actually arrived in ES2018; array destructuring and rest were ES2015.)

Classes and Modules

classes.js▶ Try it
class Payment {
  constructor(amount) { this.amount = amount; }
  get label() { return `$${this.amount}`; }
  static zero() { return new Payment(0); }
}
class CardPayment extends Payment {
  get label() { return `${super.label} by card`; }
}
console.log(new CardPayment(120).label, Payment.zero().label);
Output
$120 by card $0

Classes gave JavaScript a clear syntax for constructors, methods, getters, static members and inheritance (see "Classes" and "Class Inheritance"). Modules (import and export) gave it a standard way to split code into files ("ES Modules"). Private fields and class fields came later (ES2022).

Promises

promises.js▶ Try it
const wait = (ms, value) => new Promise((resolve) => setTimeout(() => resolve(value), ms));
 
wait(10, 120)
  .then((amount) => amount + 30)
  .then((total) => console.log("total:", total));
 
Promise.all([wait(5, "a"), wait(1, "b")]).then((values) => console.log(values));
Output
['a', 'b']
total: 150

Promises standardized asynchronous results, replacing callback pyramids, and laid the foundation for async/await (ES2017). See "Promises".

New Collections and Symbols

collections.js▶ Try it
const balances = new Map([["Navika", 120]]);
balances.set("Advitha", 45);
const grades = new Set([9, 11, 9]);
const id = Symbol("id");
 
console.log(balances.get("Advitha"), balances.size, [...grades]);
console.log(typeof id, { [id]: 1, visible: 2 });
Output
45 2 [9, 11]
symbol { visible: 2 }
FeatureLesson
Map, Set"Maps", "Sets"
WeakMap, WeakSet"WeakMap and WeakSet"
Symbol, well-known symbols"Symbols"

Iterators and Generators

generators.js▶ Try it
function* receiptNumbers(start) {
  let n = start;
  while (true) yield `R-${n++}`;
}
const gen = receiptNumbers(1001);
console.log(gen.next().value, gen.next().value);
 
const schedule = { *[Symbol.iterator]() { yield 400; yield 415; } };
console.log([...schedule]);
Output
R-1001 R-1002
[400, 415]

The iteration protocol made for...of, spread and destructuring work on any data source. See "Iterables and Iterators" and "Generators".

Meta-Programming

Proxy and Reflect let code intercept and forward fundamental object operations (see "Proxy and Reflect").

New Methods on Built-Ins

ObjectES2015 additions
Stringincludes, startsWith, endsWith, repeat, codePointAt, String.raw
NumberNumber.isInteger, isFinite, isNaN, isSafeInteger, EPSILON, MAX_SAFE_INTEGER
Mathtrunc, sign, cbrt, hypot, log2, log10...
ArrayArray.from, Array.of, find, findIndex, fill, keys, values, entries, copyWithin (includes came a year later, in ES2016)
ObjectObject.assign, Object.is, Object.setPrototypeOf, Object.getOwnPropertySymbols
RegExpThe u (Unicode) and y (sticky) flags
methods.js▶ Try it
console.log("Fee Tracker".startsWith("Fee"), "ab".repeat(3), Number.isInteger(5.0));
console.log(Array.from("abc"), [120, 85, 45].find((n) => n < 100), Object.is(NaN, NaN));
console.log(Object.assign({}, { a: 1 }, { b: 2 }), Math.trunc(-4.7));
Output
true ababab true
['a', 'b', 'c'] 85 true
{ a: 1, b: 2 } -4

Why It Took Until 2015

After ES3 (1999), an ambitious ES4 failed in 2008, and ES5 (2009) was a smaller, compatible update. ES2015 (developed under the name "Harmony") collected years of ideas into one release. The committee then decided never to do a giant release again, and switched to small yearly editions so features could ship as soon as they were ready.

In Practice

A pre-2015 Fee Tracker module, converted feature by feature:

after.js▶ Try it
class Account {
  constructor(owner, payments = []) {
    this.owner = owner;
    this.payments = payments;
  }
  get total() {
    return this.payments.reduce((sum, p) => sum + p, 0);
  }
  summary() {
    return `${this.owner} paid $${this.total} in ${this.payments.length} payments`;
  }
}
 
const accounts = [new Account("Navika", [120, 60]), new Account("Advitha")];
for (const account of accounts) console.log(account.summary());
Output
Navika paid $180 in 2 payments
Advitha paid $0 in 0 payments

Common Mistakes

Mixing var and let in the same code. Convert consistently; var keeps its function-scope surprises.

Using arrows as methods when converting. Methods that use this should use method shorthand.

Treating class as a new object model. It's syntax over prototypes (see "Prototypes").

Assuming every modern feature is ES2015. Object spread (ES2018), async (ES2017) and class fields (ES2022) came later.

Practice

Challenge: Use at least five ES2015 features (arrow function, default parameter, template literal, destructuring, Map) to build a function that groups payments by student and prints totals.

Show solution
es2015-practice.js▶ Try it
const groupTotals = (payments, currency = "USD") => {
  const totals = new Map();
  for (const { name, amount } of payments) totals.set(name, (totals.get(name) || 0) + amount);
  return [...totals].map(([name, total]) => `${name}: ${total} ${currency}`);
};
 
console.log(groupTotals([{ name: "Navika", amount: 120 }, { name: "Advitha", amount: 45 }, { name: "Navika", amount: 60 }]));
Output
['Navika: 180 USD', 'Advitha: 45 USD']

Quick check: ES2015

3 questions
1Which of these came in ES2015?
2Which ES2015 feature standardized asynchronous results?
3Object spread ({ ...obj }) arrived in which edition?

Key Takeaways

GroupHighlights
Scopelet, const
FunctionsArrows, defaults, rest, spread
SyntaxTemplate literals, destructuring, for...of
Structureclass, modules
AsyncPromises
DataMap, Set, symbols, iterators

Was this tutorial helpful?

Lesson 119 of 139