<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ashish Singh Rawat</title>
    <description>The latest articles on DEV Community by Ashish Singh Rawat (@ashish9342).</description>
    <link>https://dev.to/ashish9342</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F179551%2Fe1635d86-8736-4583-b098-7fa282368124.jpeg</url>
      <title>DEV Community: Ashish Singh Rawat</title>
      <link>https://dev.to/ashish9342</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashish9342"/>
    <language>en</language>
    <item>
      <title>hola</title>
      <dc:creator>Ashish Singh Rawat</dc:creator>
      <pubDate>Thu, 25 Nov 2021 06:57:44 +0000</pubDate>
      <link>https://dev.to/ashish9342/hola-1fo2</link>
      <guid>https://dev.to/ashish9342/hola-1fo2</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p8xtFrtb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im225sr309msgd7z7qh2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p8xtFrtb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im225sr309msgd7z7qh2.png" alt="Image description" width="880" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Constructor is no more | React</title>
      <dc:creator>Ashish Singh Rawat</dc:creator>
      <pubDate>Thu, 25 Nov 2021 06:45:37 +0000</pubDate>
      <link>https://dev.to/ashish9342/contructor-is-no-more-react-59i3</link>
      <guid>https://dev.to/ashish9342/contructor-is-no-more-react-59i3</guid>
      <description>&lt;p&gt;Yes, you read it right! There is no more constructor in class component in react.js. You must have seen the traditional react code similar to below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as per new react(v0.13.0-beta), this can be written in a new format&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was inspired by TypeScript’s property initializers.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Much cleaner way to write&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/blog/2015/01/27/react-v0.13.0-beta-1.html#es7-property-initializers"&gt;https://reactjs.org/blog/2015/01/27/react-v0.13.0-beta-1.html#es7-property-initializers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tc39/proposal-class-fields"&gt;https://github.com/tc39/proposal-class-fields&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Commenting Code | Good Practices</title>
      <dc:creator>Ashish Singh Rawat</dc:creator>
      <pubDate>Sun, 26 Sep 2021 15:43:05 +0000</pubDate>
      <link>https://dev.to/ashish9342/commenting-code-good-practices-3d23</link>
      <guid>https://dev.to/ashish9342/commenting-code-good-practices-3d23</guid>
      <description>&lt;p&gt;Imagine, you have joined a new company and given access to their source code. Now it's your sole responsibility to maintain the code and you cannot go to the guy who has written this code.&lt;/p&gt;

&lt;p&gt;As a developer, regardless of speciality, we tend to spend more time on reading others' code. Writing comments can help other developers understand the complex logic you were thinking while building it.&lt;/p&gt;

&lt;p&gt;Here are some tips that can be used while writing comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Single line comments&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This starts with &lt;code&gt;//&lt;/code&gt; and then the description of the code&lt;/li&gt;
&lt;li&gt;It’s a good idea to comment code that someone else might consider unneeded.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// execute only if array has some value&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// inline comment&lt;/span&gt;
&lt;span class="p"&gt;..&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Multiline Comments&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;These comments are generally written when you have developed a complex feature.&lt;/li&gt;
&lt;li&gt;It helps in documenting the project.&lt;/li&gt;
&lt;li&gt;It starts with a blank line starting with &lt;code&gt;/**&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;each line starts with &lt;code&gt;*&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Ends with with a blank line starting with */
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="cm"&gt;/**
 * @description This function generates the button required for Action Bar
 * @author Ashish
 * @param { Function } t =&amp;gt; translation function
 * @param { Object } history =&amp;gt; contains previous state
 * @param { Function } print =&amp;gt; property passed from parent to print
 * @returns { Array } buttons array of Objects
 * @see {@link https://stackoverflow.com/users/5282407/ashish-singh-rawat }
 * @todo Performance optimisation, removing multiple loops
 * * BELOW ARE SOME MORE META DATA, that can be used
 * @argument @async @borrows @class @classdesc @constant
 * @constructor @copyright @default @deprecated @emits
 * @enum @event @example @extends @external @field @file
 * @fileoverview @fires @function @generator @global
 * @hideconstructor @host @ignore @implements @inheritdoc @inner
 * @instance @interface @kind @lends @license @listens @member @memberof
 * @method @mixes @module @name @namespace @override @param @private @property
 * @protected @public @readonly @returns @see @since @static @summary @template
 * @this @throws @tutorial @type @typedef @var @variation @version @virtual 
 * @yields 
 **/&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getButtons&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;history&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;print&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Adding a metadata
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Add a preface/ &lt;code&gt;description&lt;/code&gt; to your comment, keep it short and what it does. No one wants to read a novel.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;parameter&lt;/code&gt; or &lt;code&gt;arguments&lt;/code&gt;, it is accepting and the &lt;code&gt;type&lt;/code&gt; of it&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Author&lt;/code&gt; this tells who has written this&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;return&lt;/code&gt; what exactly the function is returning&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;link&lt;/code&gt; a reference to other web link&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;todo&lt;/code&gt; if have written a hackfix, or you want to change the code in later stage&lt;/li&gt;
&lt;li&gt;There are other metadatas, which you can use. Just &lt;code&gt;@&lt;/code&gt; in your multi comments will the rest&lt;/li&gt;
&lt;li&gt;Eg: &lt;code&gt;example&lt;/code&gt;, &lt;code&gt;methodof&lt;/code&gt;, &lt;code&gt;private&lt;/code&gt;, &lt;code&gt;public&lt;/code&gt;, &lt;code&gt;protected&lt;/code&gt; ...&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Note:
&lt;/h6&gt;

&lt;p&gt;&lt;code&gt;type&lt;/code&gt; to be in uppercase &lt;code&gt;Boolean&lt;/code&gt;, &lt;code&gt;Object&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now if somebody is using your functions with comments it will also help them write their code. Eg:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9m24e48jzscmn13vmqoc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9m24e48jzscmn13vmqoc.PNG" alt="commenting code | good practices"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Don'ts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Writing comments for each line. Yes I have seen code where comments are written for each line or self explanatory.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Compnent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;propTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/** translation function */&lt;/span&gt;
  &lt;span class="na"&gt;translation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="cm"&gt;/* history received as props for navigation purpose */&lt;/span&gt;
  &lt;span class="na"&gt;history&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="cm"&gt;/** data from graphql response */&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Writing inappropriate description to your comment. &lt;a href="https://www.vidarholen.net/contents/wordcount/#fuck*,shit*,crap*,bastard,penguin,idiot" rel="noopener noreferrer"&gt;Swearing&lt;/a&gt; in code. Yes, developer does that.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not writing comments at all in your file.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are multiple good libraries that have good comments like &lt;a href="https://lodash.com/docs/4.17.15" rel="noopener noreferrer"&gt;lodash&lt;/a&gt;, &lt;a href="https://github.com/facebook/react" rel="noopener noreferrer"&gt;React&lt;/a&gt;, &lt;a href="https://github.com/angular/angular" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Please to refer their comment style for more.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered?answertab=votes#tab-top" rel="noopener noreferrer"&gt;Funny comments&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>codequality</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Object destructuring in Javascript | Real time example | Good Practice</title>
      <dc:creator>Ashish Singh Rawat</dc:creator>
      <pubDate>Tue, 21 Sep 2021 17:11:45 +0000</pubDate>
      <link>https://dev.to/ashish9342/object-destructuring-in-javascript-real-time-example-good-practice-5g97</link>
      <guid>https://dev.to/ashish9342/object-destructuring-in-javascript-real-time-example-good-practice-5g97</guid>
      <description>&lt;p&gt;I was working on my project and got a review comment from my colleague to put the default value for the nested object, as it could break the app.&lt;/p&gt;

&lt;p&gt;Below was the response object structure that I was getting from an API call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="na"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ashish&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;9876543210&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;only &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;number&lt;/code&gt; were getting used in the code. The code I had written previously for which I have received the comment looked as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  PROBLEM
&lt;/h3&gt;

&lt;p&gt;Now the problem with above code is, &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;if Backend doesn't share the data object. Then JS the engine will try to find someData in &lt;code&gt;undefined&lt;/code&gt;. This could have broke the application&lt;/li&gt;
&lt;li&gt;I wanted to write everything in one line, instead of destructuring multiple times&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So to avoid the above problem, I had to google and search for a good practice for javascript multilevel destructuring with default values. And here is what I got&lt;/p&gt;

&lt;h3&gt;
  
  
  SOLUTION
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;code doesn't break, as we are setting default values for the response object in the frontend.&lt;/li&gt;
&lt;li&gt;Clean code&lt;/li&gt;
&lt;li&gt;Readable (This point is argued, depends on developer perspective)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  EXPLANATION
&lt;/h3&gt;

&lt;p&gt;If you haven't tried multilevel destructuring, above code might look little confusing, let's break the above code into multiple statements&lt;/p&gt;

&lt;h5&gt;
  
  
  1. Destructuring Multilevel
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
      &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;number&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//OR&lt;/span&gt;
&lt;span class="c1"&gt;// In one line&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how we destructure a multilevel object. With parent object &lt;code&gt;data&lt;/code&gt; outside pointing to the child object &lt;code&gt;someData&lt;/code&gt; and then the child object &lt;code&gt;someData&lt;/code&gt; referring to the child object having values  &lt;code&gt;name&lt;/code&gt;and &lt;code&gt;number&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Assigning default value
&lt;/h5&gt;

&lt;p&gt;if &lt;code&gt;data&lt;/code&gt; doesn't exist in the response object, assign a default value to it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;data&lt;/code&gt; doesn't exist in response, then data with empty object is created inside the response&lt;/p&gt;

&lt;h6&gt;
  
  
  Note:
&lt;/h6&gt;

&lt;p&gt;Default values go to the right hand side and &lt;code&gt;=&lt;/code&gt; is used to assign the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
           &lt;span class="na"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
             &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="nx"&gt;number&lt;/span&gt;
           &lt;span class="p"&gt;}&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// OR&lt;/span&gt;
&lt;span class="c1"&gt;// in 1 line&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates an object with &lt;code&gt;someData&lt;/code&gt; with &lt;code&gt;name&lt;/code&gt; default value is &lt;code&gt;''&lt;/code&gt; empty string and &lt;code&gt;number&lt;/code&gt;'s default value as &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;h6&gt;
  
  
  Note:
&lt;/h6&gt;

&lt;p&gt;&lt;code&gt;''&lt;/code&gt; empty string and &lt;code&gt;null&lt;/code&gt; are falsy values.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>destructure</category>
      <category>destructuring</category>
    </item>
  </channel>
</rss>
