Tutorials Modern JavaScript (ES6+) for Beginners
Destructuring — Arrays & Objects
Learn Destructuring — Arrays & Objects in our free Modern JavaScript (ES6+) for Beginners series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.
On this page
Destructuring — Arrays & Objects
Destructuring pulls values out of arrays or objects into variables in one line. React props, API responses, and function parameters all use this pattern: const { name, email } = user.
Array destructuring
const colors = ['red', 'green', 'blue'];
const [first, second] = colors;
// first = 'red', second = 'green'
const [, , third] = colors; // skip first two
// third = 'blue'
const [head, ...rest] = colors;
// head = 'red', rest = ['green', 'blue']
Object destructuring
const user = { id: 42, name: 'Alex', email: 'alex@toolliyo.com', role: 'student' };
const { name, email } = user;
const { role: userRole } = user; // rename to userRole
// Default if missing
const { phone = 'N/A' } = user;
🌍 Real-world example — API user profile (React / Node)
async function showProfile(response) {
const data = await response.json();
const { name, email, plan = 'free' } = data.user;
return `${name} (${email}) — ${plan} plan`;
}
// Simulated API object:
showProfile({
json: async () => ({ user: { name: 'Ravi', email: 'ravi@example.com' } })
});Destructuring in function parameters
function printOrder({ orderId, items, total }) {
console.log(`Order #${orderId}: ${items.length} items, ₹${total}`);
}
printOrder({ orderId: 'A100', items: [1, 2], total: 1498 });
⚠️ Common Mistake: Destructuring undefined:
const { x } = null throws. Use defaults: const { x } = obj || {} or optional chaining (Lesson 12 preview).💡 Tip: In React:
function Card({ title, children }) { } — that is object destructuring of props.👨🏫 Teaching note: Pass a nested API JSON on screen; students write destructuring for user.name and address.city.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Junior
Detailed
Explain JavaScript in the context of Modern JavaScript (ES6+) for Beginners.
Short answer: JavaScript runs single-threaded with an event loop. Closures capture lexical scope; promises/async handle I/O without blocking the UI thread. How to structure your answer (60–90 seconds) Define JavaScript i…
Mid
Detailed
What are common mistakes teams make with Components when using Modern JavaScript (ES6+) for Beginners?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Components in plain language…
Senior
Detailed
How would you debug a production issue related to State in a Modern JavaScript (ES6+) for Beginners application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define State in plain language for…
Mid
Detailed
Compare two approaches to API integration—when would you choose each?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define API integration in plain lan…
Junior
Detailed
Describe a real-world scenario where Performance mattered in a Modern JavaScript (ES6+) for Beginners project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Performance in plain languag…
Questions on this lesson
0
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!