JavaScript ES6 Features Guide

javascript
es6
modern-js

Key Features

Template Literals

  • Multi-line strings and interpolation.
const name = 'John';
const greeting = `Hello, ${name}.
Welcome!`;

Destructuring

const user = { name: 'Alice', age: 25 };
const { name, age } = user;
console.log(name, age); // Alice 25

Spread and Rest Operators

const arr = [1, 2, 3];
const extended = [...arr, 4, 5];
console.log(extended); // [1, 2, 3, 4, 5]
 
function sum(...nums) {
  return nums.reduce((acc, num) => acc + num, 0);
}
console.log(sum(1, 2, 3)); // 6

Promises

const fetchData = () =>
  new Promise(resolve => setTimeout(() => resolve('Data fetched'), 1000));
 
fetchData().then(console.log);

Classes

class Animal {
  constructor(name) {
    this.name = name;
  }
 
  speak() {
    console.log(`${this.name} makes a noise.`);
  }
}