Skip to content
Guest
Learn JavaScript · Course Syllabus Show lessons
Data Structures & Modern Syntax · 9 min read · Beginner

Destructuring, Spread & Optional Chaining

Write concise, crash-proof JavaScript with object/array destructuring, immutable spread copies (...), and optional chaining (?.).

What you'll learn

  • Extract properties and array items cleanly with destructuring
  • Clone and merge objects or arrays immutably with the spread operator (...)
  • Read deeply nested properties safely using optional chaining (?.)

These three modern ES syntax features make your code dramatically shorter and safer:

  1. Destructuring: const { title, level = 'Beginner' } = course;
  2. Spread (...): const updated = { ...course, completed: true }; (copies without mutating course!)
  3. Optional Chaining (?.): const city = user?.profile?.address?.city ?? 'Unknown'; (returns undefined instead of throwing TypeError: Cannot read properties of undefined!)

Fill-in-the-Blank Exercise

Destructure, Spread & Optional Chain

Destructure title from course, clone tags with a new item, and safely read author.social.github.

const {  } = course;
const allTags = [tags, 'modern'];
const handle = course.authorsocialgithub ?? 'none';

Try It Yourself

Destructuring, Spread & Optional Chaining
Live Result
Console Output

No console output yet. Try calling console.log(...) in JS.

Check Your Understanding

Score: 0 / 1

1. What does `user?.settings?.theme` return if `user.settings` is undefined?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind