<?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: Syed Kamal</title>
    <description>The latest articles on DEV Community by Syed Kamal (@syedkamal3262).</description>
    <link>https://dev.to/syedkamal3262</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%2F292266%2Ffed98788-f7ec-49ee-91f5-5898232164c9.jpeg</url>
      <title>DEV Community: Syed Kamal</title>
      <link>https://dev.to/syedkamal3262</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/syedkamal3262"/>
    <language>en</language>
    <item>
      <title>Optional chaining (?.)</title>
      <dc:creator>Syed Kamal</dc:creator>
      <pubDate>Thu, 17 Sep 2020 18:53:11 +0000</pubDate>
      <link>https://dev.to/syedkamal3262/optional-chaining-48ej</link>
      <guid>https://dev.to/syedkamal3262/optional-chaining-48ej</guid>
      <description>&lt;p&gt;Optional chaining is something I know about it later this week and i found it a powerful feature to use when accessing object keys&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let personalData = {
userId: 2223 ,
userDetail:{
    name :{
    userName :{
        fullName:{
            firstName:"John",
            lastName:"Bob",
            otherName: {
                nickName:"Jonn"
            }
        }
    },
    age: 24
    }
}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;this is users object in user object  some user have parents information and some don't but we have to access it to utilize the information by calling it through &lt;strong&gt;dot(.)&lt;/strong&gt; notation,&lt;br&gt;
we are calling &lt;strong&gt;fatherName&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;personalData.userDetail.fatherName 
//VM2126:1 Uncaught TypeError: Cannot read property 'fatherName' of undefined at &amp;lt;anonymous&amp;gt;:1:34
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;it throws back an error as father name is not present in the object its something not good practice to print the &lt;strong&gt;error&lt;/strong&gt; on UI so we have to use this old way using the &lt;strong&gt;AND&lt;/strong&gt; operator&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;personalData &amp;amp;&amp;amp; personalData.userDetail 
&amp;amp;&amp;amp; personalData.userDetail.fatherName 
//undefined
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;now we are in a safe zone by using the &lt;strong&gt;AND&lt;/strong&gt; operator now it returns undefined instead of an &lt;strong&gt;error&lt;/strong&gt;,&lt;br&gt;&lt;br&gt;
here comes optional chaining to reduce syntax simply use &lt;strong&gt;(?.)&lt;/strong&gt; and it returns &lt;strong&gt;undefined&lt;/strong&gt; if the value not exist&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;personalData.userDetail.username?.fatherName
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;this is very needful when accessing nested object properties and makes us on the safe side from causing an error&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>JS Object Destructuring  </title>
      <dc:creator>Syed Kamal</dc:creator>
      <pubDate>Sat, 15 Aug 2020 16:05:11 +0000</pubDate>
      <link>https://dev.to/syedkamal3262/js-object-destructuring-95d</link>
      <guid>https://dev.to/syedkamal3262/js-object-destructuring-95d</guid>
      <description>&lt;p&gt;Destructuring object is very needful thing when you are working with objects in vanilla js or any other js frontend framework ,&lt;br&gt;
lets destructe this object Destructuring ;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let personalData = {
userId: 2223 ,
userDetail:{
    name :{
    userName :{
        fullName:{
            firstName:"John",
            lastName:"Bob",
            otherName: {
                nickName:"Jonn"
            }
        }
    },
    age: 24
    }
}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;now if you want to have &lt;strong&gt;userId&lt;/strong&gt; initialize in new variable you have to use dot notation to get the &lt;strong&gt;userId&lt;/strong&gt; from personalData object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let userIdofUser = personalData.userId;
userIdofUser; // output 2223
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;but now we have more simpler syntax for this using just curly braces containing exact key name of whatever key you required to initialize.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let {userId} = personalData;
userId; // output 2223
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;this way you got variable userId of personalData easily initialize in new variable, you can also rename the userId with the desired variable name whatever you want eg: &lt;strong&gt;idofUser1&lt;/strong&gt; separated by a colon with the key name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let {userId : idofUser1} = personalData;
idofUser1; // output 2223
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Destructure whatever level you want , for suppose you want &lt;strong&gt;nickName&lt;/strong&gt; directly initialize to some variable user1NickName you can do it too obvious&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let {userDetail:{name : {userName : {fullName: {otherName : {nickName : user1NickName }  } } }}}= personalData; 
user1NickName ;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;now user1NickName have that value &lt;strong&gt;"Jonn"&lt;/strong&gt; ;)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
      <category>vue</category>
    </item>
  </channel>
</rss>
