ES6 (ECMAScript 2015) was a major update introducing arrow functions, classes, modules, destructuring, and many other modern JavaScript features that transformed the language.
June 2015
ES6 (ECMAScript 2015) was a major update introducing arrow functions, classes, modules, destructuring, and many other modern JavaScript features that transformed the language.
Try out JavaScript code examples and experiment with features in the official TypeScript playground.
Open JavaScript PlaygroundShorter syntax for writing function expressions with lexical this binding.
// Traditional function
function add(a, b) { return a + b; }
// Arrow function
const add = (a, b) => a + b;
// With single parameter
const square = x => x * x;Syntactical sugar over JavaScript's prototype-based inheritance.
class Person {
constructor(name) {
this.name = name;
}
greet() {
return `Hello, ${this.name}!`;
}
}
const person = new Person("John");
console.log(person.greet()); // Hello, John!Extract values from objects and arrays into distinct variables.
// Array destructuring
const [a, b, ...rest] = [1, 2, 3, 4, 5];
console.log(a, b, rest); // 1, 2, [3, 4, 5]
// Object destructuring
const { name, age } = { name: "John", age: 30 };
console.log(name, age); // John, 30String literals that allow embedded expressions and multiline strings.
const name = "World";
const greeting = `Hello, ${name}!
This is a multiline
string.`;
console.log(greeting);
// Hello, World!
// This is a multiline
// string.Native module system for organizing and sharing code.
// math.js
export const add = (a, b) => a + b;
export const multiply = (a, b) => a * b;
export default class Calculator {}
// main.js
import Calculator, { add, multiply } from "./math.js";
console.log(add(2, 3)); // 5