Lab 01: ES6 Destructuring & Spread
Overview
Step 1: Array Destructuring
// Basic array destructuring
const [first, second, third] = [10, 20, 30];
console.log(first, second, third); // 10 20 30
// Skipping elements
const [, , last] = [1, 2, 3];
console.log(last); // 3
// Default values
const [a = 0, b = 0, c = 0] = [1, 2];
console.log(a, b, c); // 1 2 0
// Swapping variables
let x = 1, y = 2;
[x, y] = [y, x];
console.log(x, y); // 2 1Step 2: Object Destructuring
Step 3: Nested Destructuring
Step 4: Rest Parameters
Step 5: Spread Operator
Step 6: Computed Property Names
Step 7: Shorthand Methods & Property Shorthand
Step 8: Capstone — Config Parser
Summary
Feature
Syntax
Use Case
Last updated
