JavaScript has evolved significantly over the years, and ES6 (also known as ECMAScript 2015) introduced a wide range of new features that improved the language in many ways. Below are some of the key features of ES6 that you should be aware of.

1. Let and Const

One of the most important changes in ES6 is the introduction of let and const keywords for variable declarations. These provide block scope for variables, which means they are limited to the block in which they are declared, unlike var which is function-scoped.

if (true) {
  let a = 10;
  console.log(a); // 10
}

console.log(a); // ReferenceError: a is not defined

2. Arrow Functions

Arrow functions provide a more concise syntax for writing functions. They are particularly useful when dealing with callbacks.

const numbers = [1, 2, 3, 4, 5];

const doubled = numbers.map(number => number * 2);
console.log(doubled); // [2, 4, 6, 8, 10]

3. Template Literals

Template literals provide an easy way to create multi-line strings and embed expressions inside strings.

const name = "John";
const age = 30;

console.log(`My name is ${name} and I am ${age} years old.`);

4. Promises

Promises are a more robust way to handle asynchronous operations in JavaScript. They help in managing asynchronous operations in a more linear and readable manner.

function fetchData() {
  return new Promise((resolve, reject) => {
    // Simulate an asynchronous operation
    setTimeout(() => {
      resolve("Data fetched successfully");
    }, 2000);
  });
}

fetchData().then(data => console.log(data));

5. Modules

ES6 introduced a module system that allows you to split your code into separate files and import/export them as needed.

// myModule.js
export function sayHello() {
  return "Hello!";
}

// main.js
import { sayHello } from './myModule.js';
console.log(sayHello()); // Hello!

For more information on ES6 features, you can read our comprehensive guide on ES6 Features.

Modern JavaScript