JavaScript Fundamentals
ES6+ Features
ES6+ Features
Section titled “ES6+ Features”Modern JavaScript (ES6 and beyond) introduced powerful new features.
Destructuring
Section titled “Destructuring”Arrays
Section titled “Arrays”const [first, second, ...rest] = [1, 2, 3, 4, 5];// first = 1, second = 2, rest = [3, 4, 5]
// Swap variableslet a = 1, b = 2;[a, b] = [b, a];Objects
Section titled “Objects”const { name, age, city = "Unknown" } = person;
// Rename variablesconst { name: userName, age: userAge } = person;
// Nested destructuringconst { address: { street, zip } } = person;Spread & Rest
Section titled “Spread & Rest”// Spread arraysconst arr1 = [1, 2, 3];const arr2 = [...arr1, 4, 5]; // [1, 2, 3, 4, 5]
// Spread objectsconst obj1 = { a: 1, b: 2 };const obj2 = { ...obj1, c: 3 }; // { a: 1, b: 2, c: 3 }
// Rest parametersfunction sum(...numbers) { return numbers.reduce((a, b) => a + b, 0);}Template Literals
Section titled “Template Literals”const name = "World";const greeting = `Hello, ${name}!`;
// Multi-line stringsconst html = ` <div> <h1>${title}</h1> <p>${content}</p> </div>`;
// Tagged templatesfunction highlight(strings, ...values) { return strings.reduce((acc, str, i) => `${acc}${str}<mark>${values[i] || ""}</mark>`, "");}Modules
Section titled “Modules”// Named exports (math.js)export const PI = 3.14159;export function add(a, b) { return a + b; }
// Default export (greeting.js)export default function greet(name) { return `Hello, ${name}!`;}
// Importingimport greet from "./greeting.js";import { PI, add } from "./math.js";import * as math from "./math.js";Optional Chaining & Nullish Coalescing
Section titled “Optional Chaining & Nullish Coalescing”// Optional chainingconst city = user?.address?.city;const result = obj?.method?.();
// Nullish coalescingconst value = null ?? "default"; // "default"const zero = 0 ?? "default"; // 0 (not "default"!)Other Features
Section titled “Other Features”// Object shorthandconst name = "John";const person = { name, greet() { return `Hi, ${this.name}`; } };
// Computed property namesconst key = "dynamic";const obj = { [key]: "value" };
// Array methods[1, 2, 3].includes(2); // true[1, 2, 3].find(x => x > 1); // 2[1, 2, 3].findIndex(x => x > 1); // 1Object.entries({ a: 1 }); // [["a", 1]]Congratulations!
Section titled “Congratulations!”You’ve completed the JavaScript tutorial series! Continue with:
Tutorials