W3Teacher
  • Explore
    Browse by field
    Artificial Intelligence Accounting & Finance Information Technology
    Show all fields
  • Interview Q&A
    • All Interview Questions
    • Beginner
    • Intermediate
    • Advanced
  • Practice
    • MCQs
    • Quizzes
    • Mock Interviews
  • About
  • Sign in
  • Get Started
  1. Home
  2. Search: Destructuring
  3. JavaScript
  4. Destructuring, Spread & Rest
  5. Question
All 10 Destructuring, Spread & Rest questions
More in Destructuring, Spread & Rest
How do you destructure values out of an array? What does the spread operator (...) do when used on an array? How do you assign default values while destructuring? How does the rest parameter differ from the spread operator, even though they use the same '...' syntax? How do you use spread to shallow-copy and merge objects? How do you destructure nested objects and arrays in one statement? Why must the rest element be the LAST element in a destructuring pattern? How can you use destructuring to swap two variables without a temporary variable? How do computed property names interact with object destructuring?
Advertisement
Back to results for “Destructuring”
JavaScript › Destructuring, Spread & Rest

How do you destructure properties out of an object?

Beginner

Answer

Object destructuring pulls named properties into variables using curly-brace syntax; the variable names must match the property names unless you rename them.
const user = { name: 'Sam', age: 30 };
const { name, age } = user;
console.log(name); // 'Sam'
Real-world example Extracting just the fields you need from a large API response object.

Common follow-ups: How do you rename a destructured variable?

Objects Property Descriptors & Immutability
Previous question How do you destructure values out of an array? Next question What does the spread operator (...) do when used on an array?
All 10 Destructuring, Spread & Rest questions
W3Teacher

Learn technologies. Ace technical interviews.


    Learn
    • Technologies
    • Tutorials
    • Interview Questions
    • MCQs
    Practice
    • Quizzes
    • Mock Interviews
    • Bookmarks
    • Dashboard
    Get the latest questions & tips

    Fresh interview questions and practice tips, straight to your inbox.

    Company
    • About
    • Contact us
    • Privacy Policy
    • Terms & Conditions

    © 2026 W3Teacher. All rights reserved.