Modern JavaScript: 7 ES6+ Features Every Developer Should Know
If you learned JavaScript before 2015, you might remember a language full of quirks, callbacks, and
the dreaded var keyword. But JavaScript has grown up.
Starting with ES6 (ECMAScript 2015) and continuing with yearly updates, Modern JavaScript is cleaner, more powerful, and easier to read. Here are the top features you need to be using today.
1. Let and Const (RIP Var)
The var keyword had a major flaw: it didn't respect block scope (like inside an
if statement). This led to weird bugs.
- const: Use this by default. It means the variable cannot be reassigned.
- let: Use this only if you need to change the value later (like in a loop).
// Old
var name = "John";
// New
const name = "John"; // Can't change
let age = 30; // Can change
2. Arrow Functions
Arrow functions provide a shorter syntax and, crucially, they don't bind their own this.
This solves the classic "self = this" hack.
// Old
function add(a, b) {
return a + b;
}
// New
const add = (a, b) => a + b;
3. Template Literals
Stop using the plus sign to concatenate strings. Template literals allow you to embed variables
directly into strings using backticks (`).
const name = "Alice";
// Old
console.log("Hello, " + name + "!");
// New
console.log(`Hello, ${name}!`);
4. Destructuring
Destructuring allows you to unpack values from arrays or properties from objects into distinct variables. It's incredibly useful for API responses.
const user = { name: "Bob", age: 25, city: "Paris" };
// Old
const name = user.name;
const age = user.age;
// New
const { name, age } = user;
5. Default Parameters
You can now define default values for function parameters directly in the function signature.
// Old
function greet(name) {
name = name || "Guest";
console.log("Hello " + name);
}
// New
const greet = (name = "Guest") => {
console.log(`Hello ${name}`);
}
6. Async / Await
This is arguably the biggest game-changer. It allows you to write asynchronous code (like fetching data) that looks and behaves like synchronous code. No more "Callback Hell."
// Old (Promises)
fetch('/api/user')
.then(response => response.json())
.then(data => console.log(data));
// New (Async/Await)
async function getUser() {
const response = await fetch('/api/user');
const data = await response.json();
console.log(data);
}
7. Modules (Import / Export)
JavaScript now has a native module system. You can split your code into multiple files and import them where needed, without relying on external tools like Webpack (though tools are still useful for bundling).
// math.js
export const add = (a, b) => a + b;
// main.js
import { add } from './math.js';
console.log(add(2, 3));
Conclusion
These features aren't just "syntactic sugar." They make your code safer, more readable, and easier to maintain. If you're still writing "legacy" JavaScript, pick one of these features and start using it today.
Try It Out: Open our Live HTML Viewer, switch the language to JavaScript (or just use script tags), and try writing an async function. It works right in your browser!