100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What Is Destructuring Assignment in JavaScript?

Learn JavaScript destructuring assignment for arrays and objects, with defaults, renaming, rest patterns, and examples.

easyQ44 of 224 in Web Development Est. time: 4 minsLast updated:
Open Code Lab
44 / 224

Expected Interview Answer

Destructuring assignment is a JavaScript syntax that unpacks values from arrays or properties from objects into distinct variables in a single expression, using array-literal-like or object-literal-like patterns on the left side of an assignment instead of accessing each value individually.

Array destructuring, `const [a, b] = arr`, assigns by position — the first element to `a`, the second to `b` — and supports skipping elements with extra commas and collecting the remainder with a rest pattern, `const [first, ...rest] = arr`. Object destructuring, `const { name, age } = obj`, assigns by matching property key names, and can rename with `{ name: userName }`, provide default values with `{ age = 18 }` for when the property is missing, and pull nested values with `{ address: { city } }`. Destructuring is used constantly in function parameters — `function greet({ name, age = 18 }) {}` — to make a function's expected shape self-documenting, and in module imports, `import { useState } from "react"`, which is object destructuring applied to the exported namespace. It is purely a syntactic convenience for extraction; it does not change the underlying data, and it throws only if you try to destructure a property from null or undefined at the top level.

  • Extracts multiple values in one concise statement instead of repeated dot/bracket access
  • Function parameter destructuring self-documents the expected object shape
  • Supports default values and renaming inline, reducing boilerplate
  • Enables clean swapping and rest/spread patterns for arrays and objects

AI Mentor Explanation

Destructuring is like a selector pulling specific named players straight out of a squad list — "give me the captain and the wicketkeeper" — instead of scanning the whole roster and assigning each one manually by index. If a named role is missing, a default reserve can be assigned automatically, and any player not explicitly named can be swept into a “remaining squad” group. This is exactly how `const { captain, keeper, ...rest } = squad` extracts named properties directly by matching key, defaults included. It replaces a series of separate lookups with one declarative unpacking statement.

Step-by-Step Explanation

  1. Step 1

    Choose a pattern shape

    Use `[a, b]` for positional array unpacking or `{ key1, key2 }` for named object unpacking.

  2. Step 2

    Assign the pattern

    Place the pattern on the left of `=`, the array/object to unpack on the right: `const { name } = user`.

  3. Step 3

    Add defaults or renames as needed

    Use `{ age = 18 }` for a default when missing, or `{ name: userName }` to bind under a different variable name.

  4. Step 4

    Use rest to capture the remainder

    `const { id, ...rest } = obj` or `const [first, ...others] = arr` collects everything not explicitly named.

What Interviewer Expects

  • Clear distinction between array (positional) and object (by-key) destructuring
  • Knowledge of default values and renaming syntax
  • Awareness of the rest pattern for collecting remaining elements/properties
  • A practical example, such as function parameter destructuring or module imports

Common Mistakes

  • Confusing array destructuring (positional) with object destructuring (by property name)
  • Forgetting that destructuring a property from null/undefined throws a TypeError
  • Not knowing default values only apply when the property is undefined, not null
  • Overusing deeply nested destructuring patterns that hurt readability

Best Answer (HR Friendly)

Destructuring lets you pull specific values out of an array or object directly into their own variables in one line, instead of accessing each one separately. It is commonly used to cleanly extract a few named fields from a function's input object, and it is also what you are doing every time you write an import statement like importing useState from React.

Code Example

Array and object destructuring with defaults, renaming, and rest
// Array destructuring
const coords = [10, 20, 30]
const [x, y, ...restCoords] = coords
console.log(x, y, restCoords) // 10 20 [30]

// Object destructuring with rename + default
const user = { name: 'Ada', role: 'engineer' }
const { name: userName, age = 30, ...otherFields } = user
console.log(userName, age, otherFields) // Ada 30 { role: 'engineer' }

// Function parameter destructuring
function greet({ name, age = 18 }) {
  return `Hi ${name}, age ${age}`
}
console.log(greet({ name: 'Sam' })) // Hi Sam, age 18

Follow-up Questions

  • How does destructuring a nested object property work, e.g. `{ address: { city } }`?
  • Why does `const { x } = null` throw, but `const { x } = undefined` also throws?
  • How is destructuring used in ES module import statements?
  • How would you swap two variables using array destructuring without a temp variable?

MCQ Practice

1. What does `const [a, b] = [1, 2, 3]` assign to `b`?

Array destructuring assigns by position, so b gets the second element.

2. When does a default value in destructuring apply?

Destructuring defaults trigger specifically on undefined, not on null or falsy values.

3. What does `const { id, ...rest } = obj` do?

The rest pattern gathers any properties not explicitly destructured into a new object.

Flash Cards

Array vs object destructuring?Array is positional (by index); object is by matching property key name.

When do defaults apply?Only when the value is undefined, not null or other falsy values.

What does rest (...) do in destructuring?Collects remaining unmatched elements/properties into a new array/object.

Common real-world use?Function parameter destructuring and ES module named imports.

1 / 4
44 / 224

Continue Learning

Frequently Asked Questions

21 categories · pick one to explore

Where can I practice technical interview questions for free in India?
SkillVeris offers a free interview questions section with readiness scoring, so you can practice technical interview questions at no cost from anywhere in India or worldwide. Questions span AI/ML, programming, web development, DevOps, cloud and security. Combine them with Code Lab for hands-on coding practice and the AI Mentor for instant explanations whenever an answer confuses you.
How do I prepare for a coding interview if I am a complete beginner?
Start by learning one language well, then practice small problems daily before attempting interview questions. On SkillVeris you can take a free structured programming course with 24–40 lessons, write code in the in-browser Code Lab across 6 languages, and then move to the interview questions bank with readiness scoring to measure how prepared you actually are.
What is interview readiness scoring and how does it work?
Interview readiness scoring measures how prepared you are for a technical interview based on your performance across practice questions. On SkillVeris, as you answer interview questions, your readiness score updates so you can see weak topics before the real interview. It turns vague confidence into a concrete signal, telling you which areas need more revision and which are already strong.
How long does it take to get interview ready for a developer job?
Most beginners need a few months of consistent practice to feel interview ready, though timelines vary with background and daily study time. A practical route is finishing a structured SkillVeris course, which includes 24–40 lessons, module assessments and a final exam at an 80 percent pass mark, then drilling the free interview questions until your readiness score is consistently strong.
What are the most common technical interview topics for freshers?
Freshers are commonly tested on programming fundamentals, data structures, problem solving, databases, and basics of the role's stack such as web development or cloud. SkillVeris covers these through 37 free courses, a glossary of around 2,000 terms for quick definitions, cheat sheets for revision, and interview questions with readiness scoring so you can practise exactly what interviewers usually ask.
Can I practice coding interview prep without installing anything?
Yes, SkillVeris Code Lab runs entirely in your browser, so you can practice coding interview prep without installing compilers or editors. It supports 6 languages across 15 categories of exercises. Pair Code Lab sessions with the interview questions bank and readiness scoring, and you have a complete free preparation setup that works on any machine with an internet connection.
How do I explain technical concepts clearly in an interview?
Practice explaining each concept through a simple analogy first, then add the technical detail, because interviewers value clarity over jargon. SkillVeris teaches with its Learn Through Hobbies method, explaining concepts through cricket, music, gaming, cooking and eight more domains. Learning a topic through an analogy gives you a ready-made, memorable way to explain it when an interviewer asks.
Are there free mock interview resources for software engineers?
SkillVeris provides free interview questions with readiness scoring, which works like a self-paced mock interview you can repeat any time. You answer real-style technical questions, get scored, and see where you stand. The AI Mentor is available 24/7 to explain any answer at Quick, Detailed or Deep-dive depth, acting like an always-available interviewer who never gets tired.
How should I prepare for an AI or machine learning interview?
Cover ML fundamentals, Python, and modern topics like LLMs and RAG, then practise explaining projects clearly. SkillVeris has free AI/ML courses including Python for AI and ML, Large Language Models and Retrieval-Augmented Generation, each with 24–40 lessons and assessments. After finishing, use the interview questions bank and readiness scoring to confirm you can answer under pressure.
What should I revise the night before a technical interview?
Revise concise summaries rather than learning anything new: core definitions, common patterns, and your own project stories. SkillVeris cheat sheets and study notes are built exactly for this kind of quick revision, and the glossary of around 2,000 terms lets you verify any definition fast. A short readiness-score check on the interview questions bank confirms nothing critical is shaky.
How do I prepare for a DevOps interview with no work experience?
Build demonstrable knowledge through structured learning and hands-on practice, since you cannot point to job experience. SkillVeris offers free DevOps, Docker and Kubernetes related courses within its 37-course catalog and a DevOps Engineer learning path. Complete the courses, earn certificates by passing the final exams, then use the interview questions section to rehearse common DevOps scenarios.
Do certificates help in clearing technical interviews?
Certificates alone do not clear interviews, but they signal structured learning and give interviewers a starting point for questions. SkillVeris awards certificates when you pass a course final exam at 80 percent, after 24–40 lessons and module assessments, so the certificate reflects genuine effort. Pair it with practised interview answers and Code Lab projects to make a stronger impression.
How can I improve my problem solving speed for coding interviews?
Speed comes from repetition on progressively harder problems, not from rushing. Practise daily in SkillVeris Code Lab, which offers in-browser coding in 6 languages across 15 categories, and time yourself on interview questions. Review every mistake with the AI Mentor, which explains solutions 24/7 at Quick, Detailed or Deep-dive depth, so each session genuinely improves your pattern recognition.
What questions are asked in a Python technical interview?
Python interviews typically cover data types, functions, comprehensions, OOP, error handling and libraries relevant to the role, such as ML packages for AI positions. SkillVeris interview questions include Python topics, and its free Python for AI and ML course builds the underlying knowledge across 24–40 lessons. Readiness scoring then shows whether your Python answers are interview grade.
How do I handle interview questions I don't know the answer to?
Say what you do know, reason aloud toward an approach, and be honest about the gap, because interviewers value thinking over bluffing. Reduce how often this happens by broadening fundamentals: SkillVeris study notes, cheat sheets and the roughly 2,000-term glossary fill knowledge gaps quickly, and readiness scoring highlights weak areas before an interviewer ever finds them.
Is there a free way to check my interview readiness before applying for jobs?
Yes, SkillVeris interview questions come with readiness scoring, all completely free, so you can measure preparation before applying. Once your score looks solid, browse the SkillVeris Jobs page, which aggregates live roles across India, UK, USA, Germany and Remote with salary and experience filters, and apply knowing your technical preparation has been objectively tested.
How do I prepare for web developer interview questions?
Focus on JavaScript fundamentals, your framework of choice, HTTP basics, and building things you can discuss. SkillVeris offers free web development courses among its 37-course catalog, plus a Full Stack Java Developer learning path. After the courses, drill the interview questions bank, practise coding tasks in Code Lab, and use readiness scoring to verify you cover typical frontend and backend topics.
Can the AI Mentor help me practice interview answers?
Yes, the SkillVeris AI Mentor answers questions 24/7 and can explain any concept at Quick, Detailed or Deep-dive depth, which makes it useful for rehearsing interview explanations. Ask it to clarify a topic, then try explaining it back in your own words. Combined with the interview questions bank and readiness scoring, it becomes a free, always-available practice partner.
What is the best free platform for technical interview prep in 2026?
SkillVeris is a strong free option because it combines structured learning with dedicated interview preparation in one place. You get 37 free courses, interview questions with readiness scoring, an in-browser Code Lab for hands-on practice, cheat sheets and study notes for revision, and a 24/7 AI Mentor. Everything is free, which matters for learners in India and worldwide.
How do I stay calm and confident during a technical interview?
Confidence comes from evidence of preparation, so build that evidence deliberately. Complete a SkillVeris course, pass its final exam at the 80 percent bar, and watch your readiness score climb on the interview questions bank. Knowing you have explained concepts through analogies, coded in Code Lab, and scored well on practice questions gives you genuine, grounded calm on the day.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse