MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Object Destructuring in Depth0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
6.1Object.keys, Object.values, Object.entries6.2Object.assign()6.3Spread in Objects6.4Object Destructuring in Depth
HomeTutorialsJavaScript for IntermediateObject Destructuring in Depth
Callbacks

Object Destructuring in Depth

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Object destructuring is a powerful syntax introduced in ES6 that allows you to extract properties from objects and bind them to distinct variables. Mastering advanced destructuring techniques—including default values, aliasing, nested pattern matching, and function parameter destructuring—is fundamental for writing concise modern JavaScript.


1. Property Renaming (Aliasing)

When extracting a property, you can assign it to a variable with a different name using the syntax { propertyName: newVariableName }:

1const apiResponse = {
2 usr_id: 'usr_9481',
3 fst_nm: 'Priya',
4 lst_nm: 'Sharma'
5};
6 
7// Destructure and rename to clean camelCase variables
8const {
9 usr_id: id,
10 fst_nm: firstName,
11 lst_nm: lastName
12} = apiResponse;
13 
14console.log(id); // 'usr_9481'
15console.log(firstName); // 'Priya'

2. Default Values with Fallbacks

You can specify fallback values that apply only if the extracted property is strictly undefined:

1const userProfile = {
2 username: 'alex_code',
3 role: 'editor',
4 theme: undefined // Explicitly undefined
5};
6 
7const {
8 username,
9 role = 'subscriber',
10 theme = 'system-default',
11 avatarUrl = '/images/default-avatar.png'
12} = userProfile;
13 
14console.log(theme); // 'system-default' (Fell back because value was undefined)
15console.log(avatarUrl); // '/images/default-avatar.png' (Key did not exist)
Note
Default values trigger only on undefined. Values of null, false, 0, or "" are considered defined and will not trigger the fallback default!

3. Combining Renaming and Default Values

You can rename a variable and supply a default value in the same statement:

1const settings = {
2 max_retry: null,
3 timeout_ms: undefined
4};
5 
6const {
7 timeout_ms: timeout = 3000,
8 max_retry: retries = 5
9} = settings;
10 
11console.log(timeout); // 3000 (undefined -> fallback triggered)
12console.log(retries); // null (null is defined -> NO fallback!)

4. Deep Nested Destructuring

Destructuring patterns can mirror complex nested structures to extract deeply nested values in a single step:

1const enterpriseOrder = {
2 orderId: 'ORD-774',
3 customer: {
4 name: 'Apex Corp',
5 billingAddress: {
6 city: 'Seattle',
7 postal: '98101'
8 }
9 }
10};
11 
12// Extract city directly from deep structure
13const {
14 customer: {
15 billingAddress: { city, postal }
16 }
17} = enterpriseOrder;
18 
19console.log(city); // 'Seattle'
20console.log(postal); // '98101'
21// Note: 'customer' and 'billingAddress' variables are NOT created!

5. Function Parameter Destructuring with Defaults

Destructuring function parameters creates self-documenting APIs with named arguments and default configurations:

1// Clean options configuration pattern
2function createDatabaseConnection({
3 host = 'localhost',
4 port = 5432,
5 database,
6 ssl = true
7} = {}) { // '= {}' prevents error if no argument is passed!
8 console.log(`Connecting to ${database} at ${host}:${port} (SSL: ${ssl})`);
9}
10 
11// Usage:
12createDatabaseConnection({
13 database: 'analytics_prod',
14 ssl: false
15});
16// Connecting to analytics_prod at localhost:5432 (SSL: false)
17 
18// Calling with no arguments uses all defaults safely:
19createDatabaseConnection();
20// Connecting to undefined at localhost:5432 (SSL: true)

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
In const { status: code } = response;, what variable name is created in scope?
Question 2
When does a default value in object destructuring (const { port = 8080 } = config;) trigger?
Question 3
What is the output of const { name = 'Anonymous' } = { name: null }?
Question 4
Why is = {} added to function configure({ timeout = 5000 } = {})?
Question 5
In nested destructuring const { user: { email } } = account;, which variable is declared in scope?
Next Lesson

Callbacks

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Spread in ObjectsCallbacks

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext