Lesson 7
Destructuring & Spread
Unpack arrays and objects cleanly
1What is Destructuring?✨
Destructuring is a way to unpack values from arrays or properties from objects into distinct variables. It makes your code cleaner and easier to read!
2Why Use Destructuring?🎯
- ✓ Simplifies extracting data from arrays and objects
- ✓ Reduces the amount of code you write
- ✓ Makes it clear what variables you're working with
3Array Destructuring💡
You can easily unpack values from an array. For example:
const fruits = ['apple', 'banana', 'cherry'];
const [first, second] = fruits;console.log(first); // apple
console.log(second); // banana4Object Destructuring🚀
You can also extract properties from an object. Here's how:
const person = { name: 'Alice', age: 25 };
const { name, age } = person;console.log(name); // Alice
console.log(age); // 255Using the Spread Operator🔍
The spread operator (...) allows you to expand an array or object into individual elements. It is useful for copying or merging.
6Array Example:⭐
const nums = [1, 2, 3];
const newNums = [...nums, 4, 5];console.log(newNums); // [1, 2, 3, 4, 5]7Object Example:🧩
const obj1 = { a: 1, b: 2 };
const obj2 = { ...obj1, c: 3 };console.log(obj2); // { a: 1, b: 2, c: 3 }8What You'll Build This Grade🎈
- ✓ Applications that manage data easily
- ✓ Interactive features using arrays and objects
- ✓ Cleaner code for your projects
- ✓ Fun games that utilize destructuring and spread
🎯 Practice Challenges
Master Destructuring & Spread by completing all 3 difficulty levels
Destructuring & Spread - Easy Challenge
Start with the basics. Perfect for beginners!
Destructuring & Spread - Medium Challenge
Get more challenging. Build your confidence!
Destructuring & Spread - Hard Challenge
Master this concept. Prove your skills!
🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →
Ready to Master Destructuring & Spread? 🚀
Complete the challenges, take the quiz and keep your learning streak going!
Keep learning
- ← Previous lessonLesson 6: Full ProjectsBuild production-ready web apps
- Next lesson →Lesson 8: Higher-Order FunctionsFunctions that take or return functions
- Grade 10 courseC Programming - System ProgrammingC coding course for kids.
- Student ToolsFree calculators for studentsPercentage, fraction, ratio and marks calculators with steps.
- CBSEClass 9 CBSE & NCERT study materialMaths, Science and Computer chapters with solutions.
- Future SkillsExplore future skillsAI, robotics and new-age skills explained for students.