JS Through the Years
๐ Modern JavaScript Features Since ES6 (2015โ2024)
JavaScript has evolved dramatically since ES6 (2015). Hereโs a quick reference of all the major additions to the language, broken down by year and usefulness.
๐ฆ ES6 (2015) โ The Big Upgrade
โ Syntax & Variables
let x = 10;
const y = 20;
const sum = (a = 1, b = 2) => a + b;
โ Strings & Templates
const name = 'World';
console.log(`Hello, ${name}!`);
โ Destructuring
const { name, age } = user;
const [first, second] = arr;
โ Spread & Rest
const copy = { ...original };
const sum = (...nums) => nums.reduce((a, b) => a + b);
โ Objects
const key = 'dynamic';
const obj = {
name,
[key]: 42,
};
โ Classes
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} speaks.`);
}
}
โ Promises
fetch('/api')
.then(res => res.json())
.catch(console.error);
โ Modules
// utils.js
export function greet(name) {
return `Hello, ${name}`;
}
// main.js
import { greet } from './utils.js';
โจ Post-ES6 Enhancements - Incremental Goodness
๐น ES7 (2016)
Array.prototype.includes()**exponentiation:2 ** 3
๐น ES8 (2017)
async/awaitObject.entries(),Object.values()String.padStart(),padEnd()
๐น ES9 (2018)
- Spread in objects:
{ ...obj } - Rest in objects:
const { a, ...rest } = obj Promise.prototype.finally()
๐น ES10 (2019)
Array.prototype.flat(),flatMap()Object.fromEntries()- Optional
catchbinding:catch {}
๐น ES11 (2020)
- Optional chaining:
user?.profile?.email - Nullish coalescing:
value ?? 'default' Promise.allSettled()globalThis
๐น ES12 (2021)
- Logical assignment:
a ||= 1,b &&= 2,c ??= 3 - Numeric separators:
1_000_000 String.prototype.replaceAll()
๐น ES13 (2022)
.at()method:array.at(-1)- Top-level
awaitin modules
๐น ES14+ (2023โ2024)
Array.prototype.toSorted(),toReversed(),with()- Decorators (in TC39 Stage 3)
- Record & Tuple (proposals)
- Pattern matching (proposal)
๐ง Must-Know Modern JS Features
| Feature | Why Itโs Useful |
|---|---|
async/await |
Simplifies async code |
Optional chaining (?.) |
Safe access to deep properties |
Nullish coalescing (??) |
Smart default values |
| Object & Array destructuring | Cleaner variable extraction |
Spread/rest (...) |
Concise data manipulation |
Modules (import/export) |
Better code organization |
Promises & Promise.all() |
Parallel async operations |
๐ง Bonus: Decorators (Experimental)
function Log(target, key, descriptor) {
const original = descriptor.value;
descriptor.value = function (...args) {
console.log(`Calling ${key} with`, args);
return original.apply(this, args);
};
}
class MyClass {
@Log
doThing(a, b) {
return a + b;
}
}
Decorators allow you to annotate and modify classes, methods, properties, and parameters. Theyโre widely used in frameworks like NestJS, but also powerful for things like logging, access control, and validation.
โ ๏ธ As of 2024, decorators are in Stage 3 of TC39 and available in TypeScript.