{"id":120,"date":"2026-05-04T14:45:23","date_gmt":"2026-05-04T14:45:23","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=120"},"modified":"2026-05-04T14:45:24","modified_gmt":"2026-05-04T14:45:24","slug":"object-destructuring","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring","title":{"rendered":"Object Destructuring"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Object destructuring is a modern JavaScript feature that allows developers to extract values from objects and assign them to variables in a clean and readable way. It simplifies code and reduces repetition when working with complex data structures.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Understanding Object Destructuring<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In JavaScript, objects store data in key value pairs. Normally, accessing these values requires repeating the object name multiple times. Object destructuring provides a shorter and more efficient way to access these values by unpacking them into variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Basic Syntax<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Object destructuring uses curly braces to extract values from an object and assign them to variables with the same names as the object keys.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const user = { name: &#8220;Ali&#8221;, age: 22, city: &#8220;Lahore&#8221; }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const { name, age, city } = user<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">console.log(name)<br>console.log(age)<br>console.log(city)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using Different Variable Names<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can assign object values to variables with different names using a colon.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const user = { name: &#8220;Sara&#8221;, age: 25 }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const { name: userName, age: userAge } = user<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Default Values<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If a property does not exist in the object, you can assign a default value to prevent undefined results.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const user = { name: &#8220;Ahmed&#8221; }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const { name, age = 18 } = user<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nested Object Destructuring<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Destructuring can also be used with nested objects to extract deeper values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const student = {<br>name: &#8220;Hina&#8221;,<br>marks: { math: 90, science: 85 }<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const { marks: { math, science } } = student<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Benefits of Object Destructuring<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Improves code readability and structure<br>Reduces repetitive code<br>Makes it easier to work with APIs and JSON data<br>Speeds up development process<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Common Use Cases<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Extracting data from API responses<br>Handling function parameters<br>Working with configuration objects<br>Simplifying large data structures<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conclusion<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Object destructuring is an essential JavaScript feature that helps developers write cleaner and more efficient code. By mastering this concept, you can improve your coding speed and make your applications easier to manage.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javascript\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Intermediate JavaScript > Objects > Object Destructuring<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777905864385\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777905864186\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-120","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Object Destructuring - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn object destructuring in JavaScript to extract values easily, write cleaner code, and improve development efficiency quickly\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Object Destructuring - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn object destructuring in JavaScript to extract values easily, write cleaner code, and improve development efficiency quickly\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-04T14:45:24+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=object-destructuring\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=object-destructuring\",\"name\":\"Object Destructuring - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-04T14:45:23+00:00\",\"dateModified\":\"2026-05-04T14:45:24+00:00\",\"description\":\"Learn object destructuring in JavaScript to extract values easily, write cleaner code, and improve development efficiency quickly\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=object-destructuring#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=object-destructuring\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=object-destructuring#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intermediate JavaScript > Objects > Object Destructuring\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/\",\"name\":\"Learn JavaScript with GIGZ.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Object Destructuring - Learn JavaScript with GIGZ.PK","description":"Learn object destructuring in JavaScript to extract values easily, write cleaner code, and improve development efficiency quickly","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring","og_locale":"en_US","og_type":"article","og_title":"Object Destructuring - Learn JavaScript with GIGZ.PK","og_description":"Learn object destructuring in JavaScript to extract values easily, write cleaner code, and improve development efficiency quickly","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-04T14:45:24+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring","url":"https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring","name":"Object Destructuring - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-04T14:45:23+00:00","dateModified":"2026-05-04T14:45:24+00:00","description":"Learn object destructuring in JavaScript to extract values easily, write cleaner code, and improve development efficiency quickly","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=object-destructuring#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"Intermediate JavaScript > Objects > Object Destructuring"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javascript\/#website","url":"https:\/\/gigz.pk\/javascript\/","name":"Learn JavaScript with GIGZ.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}