MT / Portfolio

Crafted with precision

00%

Status

Initializing

All articlesjavascript

Modern JavaScript ES6+: Essential Features Every Developer Should Know

By Md Moniruzzaman Tonoy · · 12 min read

Modern JavaScript ES6+: Essential Features Every Developer Should Know

Introduction

JavaScript has evolved significantly over the years. Modern ECMAScript features help developers write cleaner, more readable, and maintainable code.

Whether you work with React, Node.js, or browser applications, understanding modern JavaScript is essential.

1. let and const

Modern JavaScript provides let and const for block-scoped variable declarations.

const name = "Moniruzzaman";
let experience = "Learning JavaScript";

experience = "Building Applications";

Use const by default and let when reassignment is necessary. Avoid var in modern code unless working with legacy requirements.

2. Arrow Functions

Arrow functions provide a concise function syntax and have lexical this behavior.

const greet = (name) => {
  return `Hello, ${name}!`;
};

console.log(greet("Developer"));

3. Template Literals

Template literals make string interpolation and multiline strings easier.

const product = "Laptop";
const price = 65000;

const message = `The ${product} costs ${price} BDT.`;

4. Destructuring

Destructuring extracts values from arrays and properties from objects.

const user = {
  name: "Rahim",
  role: "Developer"
};

const { name, role } = user;

const colors = ["red", "blue"];
const [primary, secondary] = colors;

5. Spread and Rest Syntax

Spread syntax expands iterable values or object properties, while rest syntax collects remaining values.

const oldUser = {
  name: "Rahim",
  age: 22
};

const updatedUser = {
  ...oldUser,
  role: "Developer"
};

function sum(...numbers) {
  return numbers.reduce((total, number) =>
    total + number, 0
  );
}

6. Array Methods

Methods such as map, filter, find, and reduce make data transformation more expressive.

const products = [
  { name: "Laptop", price: 60000 },
  { name: "Mouse", price: 800 },
  { name: "Keyboard", price: 2500 }
];

const affordable = products.filter(
  product => product.price < 5000
);

const names = products.map(
  product => product.name
);

const total = products.reduce(
  (sum, product) => sum + product.price,
  0
);

7. JavaScript Modules

Modules help organize code into reusable files. ES modules use export and import.

// math.js
export const add = (a, b) => a + b;

// app.js
import { add } from "./math.js";

console.log(add(10, 20));

8. Promises and Async/Await

Promises represent the eventual completion or failure of asynchronous operations. Async/await provides a more readable syntax for working with promises.

async function getPosts() {
  try {
    const response = await fetch(
      "https://jsonplaceholder.typicode.com/posts"
    );

    if (!response.ok) {
      throw new Error("Request failed");
    }

    return await response.json();
  } catch (error) {
    console.error("Error:", error);
    return [];
  }
}

9. Optional Chaining and Nullish Coalescing

Optional chaining safely accesses nested properties. Nullish coalescing provides a fallback only when a value is null or undefined.

const city = user?.address?.city ?? "Unknown";

10. Best Practices

  • Use meaningful variable and function names.
  • Prefer const when reassignment is unnecessary.
  • Handle asynchronous errors properly.
  • Use modules to organize application code.
  • Avoid unnecessary mutations.
  • Write small, reusable functions.

Conclusion

Modern JavaScript features are essential for building professional applications. Practice these concepts through real projects and learn how they work together in React and Node.js development.

#JavaScript#ES6#Async Await#Promises#Programming