JavaScript has come a long way since its early days. With ES6 and beyond, the language introduced powerful new features that make code cleaner, shorter, and more maintainable.
If you’re still writing JavaScript the old way, here are 10 modern features you should start using today:
1. let
and const
🛡️
Block-scoped variables replace var
.
let count = 1; // can be reassigned
const PI = 3.1416; // cannot be reassigned
2. Template Literals 📜
No more messy string concatenation:
const name = "Alice";
console.log(`Hello, ${name}!`);
3. Arrow Functions ➡️
Shorter syntax and lexical this
binding:
const add = (a, b) => a + b;
4. Default Parameters 🧩
Give function parameters default values:
function greet(name = "stranger") {
return `Hello, ${name}`;
}
5. Destructuring 🔓
Extract values from arrays/objects easily:
const [x, y] = [10, 20];
const {name, age} = {name: "Bob", age: 25};
6. Spread & Rest Operators ...
✨
// Spread
const arr1 = [1, 2];
const arr2 = [...arr1, 3, 4]; // [1,2,3,4]
// Rest
function sum(...nums) {
return nums.reduce((a, b) => a + b, 0);
}
7. Classes 👩🏫
Cleaner syntax for prototypes:
class Person {
constructor(name) {
this.name = name;
}
greet() {
console.log(`Hi, I’m ${this.name}`);
}
}
8. Promises & Async/Await ⏳
Handle async code without callback hell:
async function fetchData() {
const res = await fetch("https://api.example.com");
const data = await res.json();
console.log(data);
}
9. Modules 📦
Use import
and export
to split code into files:
// utils.js
export const add = (a, b) => a + b;
// main.js
import { add } from "./utils.js";
10. Optional Chaining & Nullish Coalescing 🔗
Avoid crashes from undefined
values:
const user = {};
console.log(user?.profile?.name ?? "Guest");
🏆 Wrapping Up
These ES6+ features make JavaScript cleaner, easier, and more powerful. If you haven’t adopted them yet, start using them in your projects — your code (and your teammates) will thank you.
💬 Which modern JS feature do you use the most? Any personal favorite that saves you tons of time? Share in the comments 👇
Top comments (0)