βοΈ ES6+ Modern JavaScript Features
ES6 (ECMAScript 2015) and later versions introduced powerful new syntax and features that make JavaScript more expressive and concise. Hereβs a quick overview of the most important updates youβll use frequently in modern development.
π let & const
let count = 10; // Mutable
const PI = 3.14; // Immutable
π» Arrow Functions
// Traditional
function greet(name) {
return "Hello " + name;
}
// Arrow
const greet = name => `Hello ${name}`;
π¦ Template Literals
const user = "Alice";
console.log(`Welcome, ${user}!`);
π οΈ Destructuring
// Object
const user = { name: "Bob", age: 25 };
const { name, age } = user;
// Array
const colors = ["red", "green"];
const [first, second] = colors;
π Spread & Rest Operators
// Spread
const nums = [1, 2, 3];
const newNums = [...nums, 4, 5];
// Rest
function sum(...args) {
return args.reduce((a, b) => a + b, 0);
}
π Modules
// Exporting
export const sayHello = () => console.log("Hello");
// Importing
import { sayHello } from './utils.js';
π Default Parameters
function greet(name = "Guest") {
console.log(`Hello, ${name}`);
}
π‘ Next: Dive into classes, inheritance, and OOP with ES6+!