ES6, or ECMAScript 2015, is a version of JavaScript that has introduced some of the most drastic changes to the language, including classes, modules, promises, and generators.
ES6 is the 6th edition of the ECMAScript standard, and it brought along many powerful new features that have greatly improved the language's usability and power.
ES6 introduced two new ways to declare variables: let
and const
.
let a = 'hello'; // a variable that can be reassigned
const b = 'world'; // a variable that cannot be reassigned
ES6 introduced arrow functions, which provide a more concise syntax for writing function expressions.
const greet = (name) => `Hello, ${name}!`;
Promises are a new type of object that represent the eventual completion or failure of an asynchronous operation.
let promise = new Promise((resolve, reject) => {
let success = true;
if (success) {
resolve("Success!");
} else {
reject("Failure!");
}
});
Classes in ES6 are a simple sugar over the prototype-based inheritance and do not introduce a new inheritance model to JavaScript.
class Car {
constructor(name) {
this.name = name;
}
drive() {
console.log(`${this.name} is driving!`);
}
}
ES6 has introduced many more features, but these are the most common ones you'll see. We hope you find this tutorial helpful as you explore more about ES6.