• in
InterCourses
CoursesBlogs
0
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking○Inspect Values in the Console○Inspect the Queue Report○Trace a Faulty Calculation○Repair the Score Calculation✦Module Quiz
○Declaring Variables○let and const in Practice○Operators○Type Conversion○Group and Convert Expense Inputs○Calculate the Event Expense Total○Track a Changing Points Tally○Adjust a Ticket Price✦Module Quiz
○Conditionals○Demo: Combined Conditions Before FizzBuzz○Challenge: FizzBuzz Announcer○Switch Statement○Demo: Switch a Venue Sign○Challenge: Power Loadout○For Loops○While Loop○Break and Continue○Demo: Stop a Ticket Scan○Challenge: Number Guess Referee○Demo: Rainfall Routing Walkthrough○Exercise: Score Batch Report✦Module Quiz
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions○Demo: Ticket Pricing Walkthrough○Exercise: Shipping Labels with Defaults○Demo: Seat Ledger Closure Walkthrough○Exercise: Private Budget Ledger✦Module Quiz
○Arrays○Demo: Student Scoreboard○Challenge: Student Course Scoreboard○Array Mutation Methods○Array Slice and Concat○Array Iteration Methods○Multidimensional Arrays●Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every○Demo: Charging Rack Restock Report○Exercise: Pantry Restock Plan✦Module Quiz
○Object Key-Value Pairs○Student Course Record○Object Methods and Destructuring○Map and Set Collections○Playlist Lookup○Number and BigInt Boundaries○Ticket Ledger○JSON○Math and Date○Date Basics○Demo: Supply Bin Audit○Exercise: Volunteer Shift Audit○Demo: Workshop Attendance Feed○Exercise: Parcel Scan Feed✦Module Quiz
○String Methods○Template Literals○Regular Expressions○Demo: Build a Reminder with Template Literals○Exercise: Format Pantry Pickup Messages○Demo: Validate a Time Slot with Regex○Exercise: Validate Storage Shelf Labels✦Module Quiz
○Higher-Order Functions○Callbacks○map, filter, and reduce○Demo: Student Register with map○Challenge: Student Register○Recursion○Project - Data Transform Pipeline○Demo: Handle an Error-First Callback○Exercise: Report Seat Reservation Results○Demo: Summarize Completed Bike Rides○Exercise: Summarize Delivered Parcels✦Module Quiz
○Demo: A notebook object○OOP Introduction○Demo: Independent workshop passes○Classes○Demo: An inherited notice○Inheritance○Demo: A private seat counter○Encapsulation○Demo: Equipment desk checkout○Project: Library Checkout✦Module Quiz
○Demo: Callback Timing○Exercise: Asynchronous JavaScript○Demo: Promise Rehearsal○Exercise: Promises and Async Await○Demo: Offline API Coordination○Exercise: Async API Simulation○Demo: Partial Results Bulletin○Project: Resilient Awards Feed○Demo: Retry a Local Delivery○Project: Reliable Score Delivery✦Module Quiz

Destructuring

Mission: Setlist Vault

When a pair of values arrives together, destructuring names its parts by position. Try it with coordinates in script.js, then read the Console checkpoints.

Destructuring unpacks array values into variables based on their positions. The next module applies a similar idea to named object properties.

Array destructuring

javascript
const point = [3, 7];
const [x, y] = point;
console.log(x); // 3
console.log(y); // 7

Skipping elements

javascript
const [first, , third] = [10, 20, 30];
console.log(first); // 10
console.log(third); // 30

Rest pattern

javascript
const [head, ...tail] = [1, 2, 3, 4, 5];
console.log(head); // 1
console.log(tail); // [2, 3, 4, 5]

Swapping variables

javascript
let a = 1, b = 2;
[a, b] = [b, a];
console.log(a, b); // 2 1

Default values

javascript
const [x = 0, y = 0, z = 0] = [10, 20];
console.log(z); // 0 — default applied

Your Task

  1. Given const coords = [40.7128, -74.0060], use array destructuring to extract latitude and longitude.
  2. Given const stops = ["Harbor", "Museum", "Library"], destructure its first and third stops while skipping the middle.
  3. Write a function swapPair([a, b]) that takes a two-element array and returns it with elements swapped: swapPair([1, 2]) → [2, 1].
  4. Log Harbor to Library | lat: 40.7128 using the destructured values.
Hint 1
1 / 3
HINT 1

Array destructuring: const [a, b, c] = myArray;

HINT 2

Skip elements with commas: const [first, , third] = arr;

HINT 3

Use rest: const [head, ...tail] = arr;

Loading editor…
Press Run to execute your code.
READY
intercourses
javascript