Skip to content

Module Recap

Module 04 covered the concise syntax for working with objects and arrays — extracting values, copying structures, and merging data without mutation.

Object destructuring extracts named properties into variables. Use it in function parameters to receive named fields directly, and in array callbacks when you need multiple fields from each item.

Array destructuring extracts elements by position. Use it for function return values, variable swaps, and head/tail patterns.

Default values provide fallbacks when a property is undefined. Combine with destructuring to handle optional fields safely.

Renaming gives a destructured variable a different name. Use it to avoid conflicts or clarify intent: const { id: expenseId } = expense.

Spread expands arrays and objects into new expressions. Use [...array] and { ...obj } for copies, [...a, ...b] and { ...a, ...b } for merges, and { ...obj, field: value } for immutable field updates.

Rest collects remaining items into a variable. Use ...rest in function parameters to accept any number of arguments and in destructuring to capture everything not explicitly extracted.

With destructuring and spread, several BudgetBuddy patterns become idiomatic:

// Clean Expense constructor (object destructuring with defaults)
constructor({ id, description, amount, category = 'Other', date } = {}) { ... }
// Immutable expense update (spread)
const updated = { ...expense, amount: newAmount };
// Add expense to array without mutation (spread)
const newList = [...expenses, newExpense];
// Delete expense without mutation (filter, no spread needed)
const withoutDeleted = expenses.filter(e => e.id !== deletedId);
// Subclass passing unknown fields to super (rest + spread)
constructor({ recurrence, ...rest }) { super(rest); this.recurrence = recurrence; }

Module 05 introduces the Fetch API and Promises — the tools for requesting data from external APIs. You will fetch live currency exchange rates from the ExchangeRate-API and integrate them into BudgetBuddy’s display. This is where the app makes its first network request.

The Fetch API and Promises →