Practice & Assessment
Test your understanding of Objects, Arrays, and Destructuring
Multiple Choice Questions
6What is the output of the following? const obj = { a: 1 }; const copy = obj; copy.a = 99; console.log(obj.a);
Which array method should you use to create a new array with only elements that satisfy a condition?
What does the following destructuring do? const { a: x = 10 } = { b: 5 };
Where are methods defined with class syntax actually stored?
What does Array.prototype.splice do differently from Array.prototype.slice?
What does the 'in' operator check for on an object?
Coding Challenges
1Object Deep Merge
Write a function deepMerge(target, source) that recursively merges two plain objects. If both target and source have a key whose value is an object, recursively merge those. Otherwise, source values overwrite target values. Input: two plain objects of any depth. Output: a new merged object (do not mutate inputs). Ignore array values — treat them as primitives (source wins). Time estimate: 25 minutes.
Mini Project
In-Memory Contact Book
Build a contact book module (Node.js) that stores contacts as an array of objects { id, name, email, phone, tags }. Implement: addContact(data) using spread for immutable insertion, getContact(id) using find, searchContacts(query) using filter across name and email, updateContact(id, changes) using map and spread (returns new array), deleteContact(id) using filter, and getByTag(tag) using filter and includes. All functions must be pure — no mutation of the original array. Use destructuring in function parameters and array destructuring where natural. Export all functions. Write a short demo script that calls all six functions and logs results.
