ES6+

Use modern syntax such as let, const, arrow functions, modules, and destructuring.

JavaScript has evolved significantly over the years. In 2015, a major update called ECMAScript 2015 (ES6) introduced many new features that made JavaScript easier to write, read, and maintain. Since then, additional improvements have been added, which are commonly referred to as ES6+ features.

Modern JavaScript features help developers write cleaner code, reduce repetition, and build applications more efficiently. Today, ES6+ syntax is widely used in modern web development frameworks such as React, Vue, Angular, and Node.js.

Why ES6+ Is Important

Before ES6, some JavaScript code was lengthy and difficult to read. Modern features provide simpler ways to perform common tasks.

  • Cleaner and shorter code
  • Better readability
  • Improved developer productivity
  • Easier maintenance
  • Modern development standards

let and const

Before ES6, developers mainly used var to declare variables.

javascript
let age = 25;

const country = "India";
  • Use let when a value may change.
  • Use const when a value should remain constant.

Arrow Functions

Traditional Function

javascript
function greet() {
    return "Hello";
}

Arrow Function

javascript
const greet = () => {
    return "Hello";
};

For simple functions, arrow syntax can be even shorter:

javascript
const greet = () => "Hello";

Template Literals

Traditional Method

javascript
let name = "John";

console.log("Hello " + name);

Template Literal

javascript
let name = "John";

console.log(`Hello ${name}`);

Destructuring

javascript
const user = {
    name: "John",
    age: 25
};

const { name, age } = user;

console.log(name);

Output:

javascript
John

Spread Operator

javascript
const fruits = ["Apple", "Banana"];

const moreFruits = [...fruits, "Mango"];

console.log(moreFruits);

Output:

javascript
["Apple", "Banana", "Mango"]

Optional Chaining

javascript
const user = {
    profile: {
        name: "John"
    }
};

console.log(user.profile?.name);

If a property does not exist, JavaScript safely returns undefined instead of throwing an error.

Nullish Coalescing Operator

javascript
let username = null;

console.log(username ?? "Guest");

Output:

javascript
Guest

Real-World Example

javascript
const product = {
    name: "Laptop",
    price: 50000
};

const { name, price } = product;

console.log(`${name} costs ₹${price}`);

Output:

javascript
Laptop costs 50000

Summary

ES6+ introduced many powerful features that improved JavaScript development. Features such as let, const, arrow functions, template literals, destructuring, the spread operator, optional chaining, and nullish coalescing help developers write cleaner and more efficient code.

Let's learn with DevBrainBox AI