📦 Destructuring

Destructuring pozwala rozpakowywać listy i mapy do zmiennych.

List destructuring

let [a, b, c] = [1, 2, 3]; print(a, b, c); // 1 2 3 // Z wartościami domyślnymi let [x, y, z = 100] = [10, 20]; print(z); // 100

Map destructuring

let config = {host: "localhost", port: 8080}; let {host, port, timeout = 5000} = config; print(host); // "localhost" print(timeout); // 5000

W parametrach funkcji

fn processPoint({x, y}) { return `Point: ${x}, ${y}`; } processPoint({x: 10, y: 20});