<?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: Learner</title>
    <description>The latest articles on DEV Community by Learner (@lifelonglearner).</description>
    <link>https://dev.to/lifelonglearner</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%2F161375%2Fdcc18041-5775-4802-94b2-a4f1e0465007.jpg</url>
      <title>DEV Community: Learner</title>
      <link>https://dev.to/lifelonglearner</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lifelonglearner"/>
    <language>en</language>
    <item>
      <title>Nullish Coalescing is not as scary as it sounds</title>
      <dc:creator>Learner</dc:creator>
      <pubDate>Tue, 06 Jul 2021 13:32:07 +0000</pubDate>
      <link>https://dev.to/lifelonglearner/nullish-coalescing-is-not-as-scary-as-it-sounds-4c56</link>
      <guid>https://dev.to/lifelonglearner/nullish-coalescing-is-not-as-scary-as-it-sounds-4c56</guid>
      <description>&lt;p&gt;Nullish Coalescing Operator( &lt;strong&gt;??&lt;/strong&gt; ) is one of the features of &lt;strong&gt;ES2020&lt;/strong&gt;. It gives the ability to truly check the &lt;strong&gt;nullish&lt;/strong&gt; values. It is another logical operator other than OR ( || ) , AND ( &amp;amp;&amp;amp; ) and NOT ( ! ) operators.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;How it works?&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The operator returns its &lt;strong&gt;Right Hand Side (RHS)&lt;/strong&gt; operand when its &lt;strong&gt;Left Hand Side (LHS)&lt;/strong&gt; operand is &lt;strong&gt;null&lt;/strong&gt; or &lt;strong&gt;undefined&lt;/strong&gt;, otherwise it will return the LHS operand.&lt;/p&gt;

&lt;p&gt;Let's see how it works through some examples:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fg80cplfhgh2db2zqivnn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fg80cplfhgh2db2zqivnn.png" alt="Nullish-Coalescing-Operator-Ex-1" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, the component Search has a prop [[searchBoxPlaceholder]].&lt;br&gt;
As the prop is an optional one, so the component uses a default value when the prop is undefined. This is a best use-case of Nullish Coalescing operator because the developer doesn't wants to restrict component to always have a placeholder for the search input box. So using this an empty string can also be passed for the prop and the component will not use the default value for placeholder and would instead do not show a placeholder string, which can not be accomplished using the logical OR operator.&lt;/p&gt;

&lt;p&gt;Below are few other examples, which will give idea about more of it's use-cases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fjx7cznr82a50zsele9nh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjx7cznr82a50zsele9nh.png" alt="Few-Other-Examples" width="800" height="702"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Comparison with other similar operators&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The operator is simiar to logical &lt;strong&gt;OR&lt;/strong&gt; operator and &lt;strong&gt;Default Assignment&lt;/strong&gt; opertaor. If you would have noticed in the first example, then we are just assigning a default value to the prop [[searchBoxPlaceholder]], which can also be done in following way:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3ism6ky45675ub0jnu2f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3ism6ky45675ub0jnu2f.png" alt="Compare-With-Default-Assignment" width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above example will no doubt work, but only if the value of prop [[searchBoxPlaceholder]] is undefined. But if the value for prop is [[null]], then the default assignment will not work.&lt;/p&gt;

&lt;p&gt;Also, the logical operator &lt;strong&gt;OR&lt;/strong&gt; works in similar manner, but it works for all the falsy values. Let us see with the below example what difference comes in the evaluation for the same condition with OR operator.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fibxqg5ol1aedpgnsi191.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fibxqg5ol1aedpgnsi191.png" alt="Compare-With-OR-Operator" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, in the above example, the OR operator serves the purpose of assigning default value, in case the prop is any of the falsy values. But what if the user of the component doesn't wants to set any value for the placeholder. The OR operator will not allow to do this, as the empty string ( '' ) is a falsy value. So, now if we use &lt;strong&gt;Nullish Coalescing Operator ( ?? )&lt;/strong&gt;. We can solve this problem and prop can accept empty string and will not show a placeholder value.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The nullish coalesing operator ( ?? ) is used to assign a default value, against the nullish values (null &amp;amp;&amp;amp; undefined).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The operator has a very low prcedence in the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table" rel="noopener noreferrer"&gt;MDN Table&lt;/a&gt;. It has higher precedence than Logical AND ( &amp;amp;&amp;amp; ) and Logical OR ( || ).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The operator cannot be chained with &amp;amp;&amp;amp; and || operators without using any explicit parentheses.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Support&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check &lt;a href="https://caniuse.com/#search=nullish%20coalescing" rel="noopener noreferrer"&gt;Can I Use&lt;/a&gt; for the browser support.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Node JS support start from 14+ version.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;That's all for the article. Thanks for reading it. Please comment your feedback and suggestions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/mishraaSoumya" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; | &lt;a href="https://www.linkedin.com/in/mishraa-soumya/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Optional Chaining is amazing, here's why?</title>
      <dc:creator>Learner</dc:creator>
      <pubDate>Tue, 26 May 2020 17:43:39 +0000</pubDate>
      <link>https://dev.to/lifelonglearner/optional-chaining-is-amazing-here-s-why-2j4m</link>
      <guid>https://dev.to/lifelonglearner/optional-chaining-is-amazing-here-s-why-2j4m</guid>
      <description>&lt;p&gt;&lt;strong&gt;Optional Chaining&lt;/strong&gt; is the new javascript operator, which is included as part of EcmaScript 2020. The operator permits reading the value of a property located deep within a chain of connected objects without having to explicitly validate that each reference in the chain is valid. The operator works for validating the properties or methods in the object. They don't enable anything in terms of functionality, but they make the code a lot easy to read and write. Let's see how:&lt;/p&gt;

&lt;p&gt;I'm sure that we all in our coding experience have faced a common problem, for which we already have a solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&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="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&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;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;fullname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Soumya Mishra&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="na"&gt;wishlist&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wId_101&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wId_102&lt;/span&gt;&lt;span class="dl"&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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Error prone-version, could throw a TypeError if any intermediate key is undefined..&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wishlistItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wishlist&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's assume that the above object is for loggedIn user details along with user's wishlist data. Now, there can be users who have not added anything to their wishlist, so the wishlist property in the object might not be present for those users. But we have to pull the wishlist Ids from this object and make another request to fetch data.&lt;/p&gt;

&lt;p&gt;Till date, we would choose one of the below ways to handle such scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution&lt;/strong&gt;&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="nx"&gt;wishlistIds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;?&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;user&lt;/span&gt; &lt;span class="p"&gt;?&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wishlist&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wishlist&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;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wishlistItemCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wishlistIds&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="nx"&gt;OR&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wishlistIds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&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;data&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&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;user&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wishlist&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;wishlistIds&lt;/span&gt; &lt;span class="o"&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wishlist&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wishlistItemCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wishlistIds&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is something just for the small object, assume it for more complex object structure. Even if one writes the code correctly, it will not provide any readability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Magic Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we will see how we can achieve the above solution in just 1 line.&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="nx"&gt;wishlistItemCount&lt;/span&gt; &lt;span class="o"&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;user&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;wishlist&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This magic solution has been achieved through &lt;strong&gt;Optional Chaining (?.) Operator&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now let's see how this Operator works if the property in the object is a &lt;strong&gt;Function&lt;/strong&gt; or an &lt;strong&gt;array&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optional Chaining with Dynamic Properties / Arrays&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Optional Chaining works well with the dynamic properties with a different syntax. Let us see how:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;//  The syntax for dynamic properties or array:&lt;br&gt;
  ?.[ ]&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&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="nx"&gt;userdata&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="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;user&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="nx"&gt;Ram&lt;/span&gt; &lt;span class="nx"&gt;Kumar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;socialMediaAccounts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;twitter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;linkedIn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="na"&gt;primarySocialMedia&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;twitter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;socialLinks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;twitter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://twitter.com/mishraaSoumya&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;linkedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.linkedin.com/in/mishraa-soumya/&lt;/span&gt;&lt;span class="dl"&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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;primarySocialMedia&lt;/span&gt; &lt;span class="o"&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;user&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;primarySocialMedia&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// 'twitter'&lt;/span&gt;
&lt;span class="c1"&gt;// the value of primarySocialMedia can be different or dynamic property.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;socialMediaIUrl&lt;/span&gt; &lt;span class="o"&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;user&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;socialLinks&lt;/span&gt;&lt;span class="p"&gt;?.[&lt;/span&gt;&lt;span class="nx"&gt;primarySocialMedia&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// 'https://twitter.com/mishraaSoumya'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me explain the above example of how it works. So, In an app, a user can have multiple socialMediaAccounts, but there can be only 1 primary account, which can be different and dynamic. So, while pulling the URL for the primary social media account, a developer has to ensure that the dynamic value is a property in socialLinks object.&lt;/p&gt;

&lt;p&gt;The same syntax works with the &lt;strong&gt;arrays&lt;/strong&gt; also, where you are not sure if the index will always be part of the array. Check the below example:&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="c1"&gt;// If the `usersArray` is `null` or `undefined`,&lt;/span&gt;
&lt;span class="c1"&gt;// then `userName` gracefully evaluates to `undefined`.&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;usersArray&lt;/span&gt;&lt;span class="p"&gt;?.[&lt;/span&gt;&lt;span class="nx"&gt;userIndex&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Optional Chaining with Function Calls&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Optional Chaining operator also works with Function Calls, but with an additional syntax form.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;// Syntax for Function Calls&lt;br&gt;
?.( )&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;InputProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;onBlur&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inputProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;InputProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;onBlur&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;onChange&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onBlurHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inputProps&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;onBlur&lt;/span&gt;&lt;span class="p"&gt;?.();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, now you don't have to write multiple checks for your component props before actually calling the function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties of Optional Chaining&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The optional chaining operator has few properties: &lt;em&gt;short-circuiting&lt;/em&gt;, &lt;em&gt;stacking&lt;/em&gt;, and &lt;em&gt;optional deletion&lt;/em&gt;. Let's go through these properties with an example.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Short-Circuiting&lt;/strong&gt;: It means the if LHS of the expression evaluates to null or undefined, then the RHS is not evaluated.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;a?.[++x]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the above example, x is only incremented, if a is not null/undefined.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Stacking&lt;/strong&gt;: It means that more than 1 optional chaining operator can be used on a sequence of property accesses. Also, you can use different forms of the operator in the same sequence.
&lt;/li&gt;
&lt;/ol&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="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?.[&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;]?.&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;?.();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, you can combine all forms of optional chaining operator in a sequence.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Optional Delete&lt;/strong&gt;: It means that the delete operator can be combined with an optional chain.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, the user in the db object is only deleted if db is not null.&lt;/p&gt;




&lt;p&gt;That's all for the article. Thanks for reading it. Please comment your feedback and suggestions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/mishraaSoumya" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; | &lt;a href="https://www.linkedin.com/in/mishraa-soumya/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>optionalchaining</category>
      <category>es2020optionalchaining</category>
      <category>jsoptionalchaining</category>
    </item>
    <item>
      <title>All the ways to color your text in CSS</title>
      <dc:creator>Learner</dc:creator>
      <pubDate>Mon, 11 May 2020 07:29:58 +0000</pubDate>
      <link>https://dev.to/lifelonglearner/all-the-ways-to-color-your-text-in-css-55k5</link>
      <guid>https://dev.to/lifelonglearner/all-the-ways-to-color-your-text-in-css-55k5</guid>
      <description>&lt;p&gt;Color property in CSS is a very common one. It is used whenever there is a need to provide different colors to Text. There are many ways to provide value to this property. Let's have a look into all those ways.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Color Names
&lt;/h4&gt;

&lt;p&gt;The simple and common way is through color names like red, green, blue, orange, etc. There are a total of 140 color names in HTML and CSS color specification.&lt;/p&gt;

&lt;p&gt;Some of the common color names:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;red, orange, blue, cyan, aqua&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;orange&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;blockquote&gt;
&lt;h6&gt;I'm Orange&lt;/h6&gt;

&lt;h6&gt;I'm Red&lt;/h6&gt;

&lt;h6&gt;I'm Blue&lt;/h6&gt;

&lt;h6&gt;I'm Sea Green&lt;/h6&gt;
&lt;/blockquote&gt;

&lt;p&gt;These names are easy to remember as compared to other values for color property. All these color values represent the plain solid colors without any transparency.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Hexadecimal Values
&lt;/h4&gt;

&lt;p&gt;The word &lt;strong&gt;hexadecimal&lt;/strong&gt; refers to a numerical value that uses 16 as a base instead of 10. A hexadecimal value can have 16 values for each digit in a number:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A hexadecimal color code is a combination of [[Red]], [[Green]], [[Blue]] &amp;amp; &lt;a href="https://dev.tooptional"&gt;[Alpha]&lt;/a&gt; values. The most common format of the hex code is a 3 or 6 digit color code prefixed with &lt;strong&gt;#&lt;/strong&gt;, which is followed by color codes for Red, Green and Blue [[#RRGGBB]]. The code for each of the colors is a 2 digit hexadecimal number between [[0-9]] and ([[a-f or A-F]]).&lt;/p&gt;

&lt;p&gt;For example, these all are valid hexadecimal values:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;00, 0A, 1D, 9D, F5, 99, E4, CC&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The 2 digit hexadecimal number for each color is combined to create a 6 digit color value. If both the digit for each color code is the same, then the 6 digit color code can be written as a 3 digit color code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;valid&lt;/span&gt; &lt;span class="nt"&gt;color&lt;/span&gt; &lt;span class="nt"&gt;codes&lt;/span&gt;

&lt;span class="err"&gt;#000000&lt;/span&gt; &lt;span class="nt"&gt;or&lt;/span&gt; &lt;span class="err"&gt;#000&lt;/span&gt;
&lt;span class="nf"&gt;#FFFFFF&lt;/span&gt; &lt;span class="nt"&gt;or&lt;/span&gt; &lt;span class="nf"&gt;#FFF&lt;/span&gt; &lt;span class="nt"&gt;or&lt;/span&gt; &lt;span class="nf"&gt;#fff&lt;/span&gt; &lt;span class="nt"&gt;or&lt;/span&gt; &lt;span class="nf"&gt;#ffffff&lt;/span&gt;
&lt;span class="nf"&gt;#FF0000&lt;/span&gt; &lt;span class="nt"&gt;or&lt;/span&gt; &lt;span class="nf"&gt;#ff0000&lt;/span&gt;
&lt;span class="err"&gt;#2962&lt;/span&gt;&lt;span class="nt"&gt;ff&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📌 &lt;strong&gt;#RRGGBBAA&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can also change the transparency of color with the hexadecimal value, just by adding the optional alpha value code [[AA]] in [[#RRGGBB]] to make it [[#RRGGBBAA]].&lt;br&gt;
The AA value in #RRGGBBAA can range from the lowest value possible (00) to the highest value possible (FF). The lowest will make the colorfully transparent, which means you won’t see it anymore. The highest value will make it completely opaque, which is the default for hex codes anyway.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;color&lt;/span&gt; &lt;span class="nt"&gt;value&lt;/span&gt; &lt;span class="nt"&gt;with&lt;/span&gt; &lt;span class="nt"&gt;no&lt;/span&gt; &lt;span class="nt"&gt;alpha&lt;/span&gt; &lt;span class="nt"&gt;or&lt;/span&gt; &lt;span class="nt"&gt;fully&lt;/span&gt; &lt;span class="nt"&gt;opaque&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#FF0000&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;blockquote&gt;
&lt;h3&gt;I am completely opaque&lt;/h3&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;semi-transparent&lt;/span&gt; &lt;span class="nt"&gt;color&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#FF000080&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;blockquote&gt;
&lt;h3&gt;I am semi-transparent&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;📌 &lt;strong&gt;Browser Compatibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The browser support for #RRGGBBAA hex codes is great. IE doesn’t support it but otherwise, you should be covered. Check &lt;a href="https://caniuse.com/#feat=css-rrggbbaa" rel="noopener noreferrer"&gt;Can I Use&lt;/a&gt; for details if you’re curious.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. RGB Values
&lt;/h4&gt;

&lt;p&gt;An RGB color value is specified with the [[rgb]] function which has the following syntax:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;rgb (red, green, blue)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The value for each color in the function defines the intensity of the color. Each color value is an integer between [[0 and 255]] or a percentage value from [[0% to 100%]].&lt;/p&gt;

&lt;p&gt;For example, these all are valid RGB color values&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;valid&lt;/span&gt; &lt;span class="nt"&gt;rgb&lt;/span&gt; &lt;span class="nt"&gt;values&lt;/span&gt;

&lt;span class="nt"&gt;rgb&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;255&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nt"&gt;rgb&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%)&lt;/span&gt;
&lt;span class="nt"&gt;rgb&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="o"&gt;%)&lt;/span&gt;
&lt;span class="nt"&gt;rgb&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;89&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;55&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;255&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📌 &lt;strong&gt;RGBA&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;RGBA color values are an extension of RGB color values with an alpha value which provides opacity to the color similar to &lt;strong&gt;#RRGGBBAA&lt;/strong&gt;. An RGBA color is specified with the [[rgba()]] function, which has the following syntax&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;rgba (red, green, blue, alpha)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The alpha parameter in the above function is a number between 0.0 (fully transparent) and 1.0 (fully opaque).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;rgba&lt;/span&gt; &lt;span class="nt"&gt;value&lt;/span&gt; &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="nt"&gt;provide&lt;/span&gt; &lt;span class="nt"&gt;full&lt;/span&gt; &lt;span class="nt"&gt;opacity&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rgba&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&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;blockquote&gt;
&lt;h3&gt;I am fully opaque&lt;/h3&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;rgba&lt;/span&gt; &lt;span class="nt"&gt;value&lt;/span&gt; &lt;span class="nt"&gt;with&lt;/span&gt; &lt;span class="nt"&gt;transparency&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rgba&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.3&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;blockquote&gt;
&lt;h3&gt; I am semi-transparent &lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;📌 &lt;strong&gt;Browser Compatibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The browser support for rgba( ) is great. Check &lt;a href="https://caniuse.com/#feat=rgba" rel="noopener noreferrer"&gt;Can I Use&lt;/a&gt; for details if you’re curious.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. HSL / HSLA Values
&lt;/h4&gt;

&lt;p&gt;HSL stands for hue, saturation, and lightness which is extended with an alpha value to be HSLA. It represents a cylindrical-coordinate representation of colors. This looks syntactically similar to RGB values but the ranges are different. An HSL / HSLA color value is specified with the hsl( ) / hsla( ) function, which has the following syntax:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;hsl (hue, saturation, lightness)&lt;/p&gt;

&lt;p&gt;hsla (hue, saturation, lightness, alpha)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Hue&lt;/strong&gt;: Think of a color wheel. Around 0 and 360 degrees are reds. 120 degrees is where greens are and 240 degrees is blues. Use anything in between 0-360. Values above and below will be modulus 360.&lt;br&gt;
&lt;strong&gt;Saturation&lt;/strong&gt;: 0% is completely desaturated (grayscale). 100% is fully saturated (full color).&lt;br&gt;
&lt;strong&gt;Lightness&lt;/strong&gt;: 0% is completely dark (black). 100% is completely light (white). 50% is average lightness.&lt;br&gt;
&lt;strong&gt;alpha&lt;/strong&gt;: Opacity/Transparency value. 0 is fully transparent. 1 is fully opaque. 0.5 is 50% transparent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// hsl values - different shades of green

Green: hsl(120, 100%, 50%)
Light Green: hsl(120, 100%, 75%)
Pastel Green: hsl(120, 60%, 70%)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;hsla&lt;/span&gt; &lt;span class="nt"&gt;value&lt;/span&gt; &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="nt"&gt;provide&lt;/span&gt; &lt;span class="nt"&gt;full&lt;/span&gt; &lt;span class="nt"&gt;opacity&lt;/span&gt;

&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hsla&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&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;blockquote&gt;
&lt;h3&gt;I am fully opaque&lt;/h3&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;hsla&lt;/span&gt; &lt;span class="nt"&gt;value&lt;/span&gt; &lt;span class="nt"&gt;with&lt;/span&gt; &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nt"&gt;transparency&lt;/span&gt;

&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hsla&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.5&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;blockquote&gt;
&lt;h3&gt;I am semi-transparent&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;📌 &lt;strong&gt;Browser Compatibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The browser support for hsl( ) and hsla( ) is great. Check &lt;a href="https://caniuse.com/#feat=hsla" rel="noopener noreferrer"&gt;Can I Use&lt;/a&gt; for details if you’re curious.&lt;/p&gt;

&lt;h3&gt;
  
  
  No-Comma Color Functions in CSS
&lt;/h3&gt;

&lt;p&gt;If you have noticed, that every single color function actually needs two functions, one for transparency and one without transparency. There is a new syntax that eliminates the need for having 2 functions. This new syntax eliminates the commas between each value in the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* New Syntax */&lt;/span&gt;
&lt;span class="nt"&gt;rgb&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;0&lt;/span&gt; &lt;span class="err"&gt;128&lt;/span&gt; &lt;span class="err"&gt;255&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nt"&gt;rgb&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;0&lt;/span&gt; &lt;span class="err"&gt;128&lt;/span&gt; &lt;span class="err"&gt;255&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%)&lt;/span&gt;

&lt;span class="nt"&gt;hsl&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;198&lt;/span&gt;&lt;span class="nt"&gt;deg&lt;/span&gt; &lt;span class="err"&gt;28&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%)&lt;/span&gt;

&lt;span class="nt"&gt;hsl&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;198&lt;/span&gt;&lt;span class="nt"&gt;deg&lt;/span&gt; &lt;span class="err"&gt;28&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📌 &lt;strong&gt;Browser Compatibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The browser support is pretty good everything except IE11. Please do check &lt;a href="https://caniuse.com/#feat=mdn-css_types_color_space_separated_functional_notation" rel="noopener noreferrer"&gt;Can I Use&lt;/a&gt; for details.&lt;/p&gt;

&lt;h3&gt;
  
  
  New Color functions
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://www.w3.org/TR/css-color-4/" rel="noopener noreferrer"&gt;CSS Color Module Level 4&lt;/a&gt; has few new color functions e.g. lab( ), lch( ) &amp;amp; &lt;a href="https://alligator.io/css/color-function/" rel="noopener noreferrer"&gt;color ( )&lt;/a&gt;. All these function will accept the new syntax described above. &lt;/p&gt;

&lt;h3&gt;
  
  
  Which One to Choose? 🤔
&lt;/h3&gt;

&lt;p&gt;As there are many options to provide color values, it's a tough decision to choose the one. Based on my experience I would explain certain points for each syntax, which can help to find out the right syntax as per the use-case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Color Names&lt;/strong&gt;: Different browsers have their own idea for a particular named color. So, you may find differences in how a color [[aquamarine]] looks in different browsers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hex Codes &amp;amp; RGB Values&lt;/strong&gt;: They both come under a machine-readable format, which is not easy to understand by a dev. If you want to provide a lightness or darkness to a color you cannot provide it without changing the complete color code for both formats.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HSL/HSLA Values&lt;/strong&gt;: It is an intuitive color format that mimics the real world. I would like to explain it more with an example:&lt;/p&gt;

&lt;p&gt;For example, you're probably sitting at a desk right now. Notice the color of the desk. Let's say its a mahogany desk. It's color values would be—&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hex: #4f2017;&lt;br&gt;
RGB: rgb(79, 32, 23);&lt;br&gt;
HSL: hsl(10, 55%, 20%);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now hold your hand above it, like a couple of inches above the surface. Your hand's shadow now makes the desktop a bit darker, right? Now, it's impossible to represent this color change in hex or RGB, without changing the color itself. But in HSL, it's an absolute easy- simply decrease the Lightness value and bam! The color remains the same, but with a bit of black mixed in— basically, lessen the Lightness value.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hex: #4f2017; --------------&amp;gt; #200d09;&lt;br&gt;
RGB: rgb(79, 32, 23); ------&amp;gt; rgb(32, 13, 9);&lt;br&gt;
HSL: hsl(10, 55%, 20%); ----&amp;gt; hsl(10, 55%, 8%);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As you can see, the values of Hex and RGB have completely changed, whereas in HSL only one aspect has changed. Because of this, it becomes intuitively easy to create color schemes on the fly.&lt;/p&gt;

&lt;p&gt;So, my recommendation would be to use HSL a lot because getting accent colors from base color is very easy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where else these values can be used?
&lt;/h3&gt;

&lt;p&gt;Not only with color property, these values are also used with other css properties like &lt;strong&gt;background-color&lt;/strong&gt;, &lt;strong&gt;border-color&lt;/strong&gt;, &lt;strong&gt;caret-color&lt;/strong&gt;, &lt;strong&gt;text-decoration-color&lt;/strong&gt;, &lt;strong&gt;outline-color&lt;/strong&gt;, &lt;strong&gt;box-shadow&lt;/strong&gt;, &lt;strong&gt;linear-gradient&lt;/strong&gt;.&lt;/p&gt;




&lt;p&gt;That’s all for now for this article. I have tried to share my knowledge, hoping to help others. Please comment your valuable suggestions and feedback.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/mishraasoumyaa"&gt;Dev.to&lt;/a&gt; | &lt;a href="https://twitter.com/mishraaSoumya" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>csscolorvalue</category>
      <category>csscolors</category>
      <category>hsla</category>
      <category>csstextcolor</category>
    </item>
    <item>
      <title>Use Case for Babel Configuration Files</title>
      <dc:creator>Learner</dc:creator>
      <pubDate>Sun, 26 Jan 2020 08:14:35 +0000</pubDate>
      <link>https://dev.to/lifelonglearner/use-case-for-babel-configuration-files-54ok</link>
      <guid>https://dev.to/lifelonglearner/use-case-for-babel-configuration-files-54ok</guid>
      <description>&lt;p&gt;One cannot imagine working on a Javascript project without babel. Whether it's NodeJs or browsers, you need babel.&lt;/p&gt;

&lt;p&gt;Babel provides 2 ways for the configuration:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;babel.config.json (there are multiple supported extension)&lt;/li&gt;
&lt;li&gt;babelrc.json (there are multiple supported extension)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, the point comes which of the above files to be used as per your use case. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;babel.config.json&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This has been included with the babelv7.x to resolve multiple project-wide Issues. This configuration file comes into the picture when you just want to have a single configuration for the whole project. If you are using a mono-repo or you want to compile your node_modules.&lt;/p&gt;

&lt;p&gt;This file is created at the root of your project, where package.json resides. This configuration file applies broadly to the project and even applies plugins and presets to the node modules folder.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;babelrc.json&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You have a configuration that only applies to a single part of your project. It allows you to create independent configurations for subsections of a package.&lt;/p&gt;

&lt;p&gt;Also, both the config files can be used together in a case where you want to have a project-wide configuration, but also need some independent configurations.&lt;/p&gt;

&lt;p&gt;For example, a mono-repo can have a project-wide configuration, but each of its packages can be build using a babelrc.json file. &lt;/p&gt;

&lt;p&gt;Hope, that my learnings will help someone.&lt;/p&gt;

&lt;p&gt;Happy Learning! &lt;/p&gt;

</description>
      <category>babeljs</category>
      <category>babelconfiguration</category>
      <category>babelconfigfiles</category>
    </item>
  </channel>
</rss>
