<?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: Saran Chakravarthi</title>
    <description>The latest articles on DEV Community by Saran Chakravarthi (@saran_chakravarthi).</description>
    <link>https://dev.to/saran_chakravarthi</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%2F666365%2Fa9998d73-df05-420d-8ff4-0ecab2131daf.png</url>
      <title>DEV Community: Saran Chakravarthi</title>
      <link>https://dev.to/saran_chakravarthi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saran_chakravarthi"/>
    <language>en</language>
    <item>
      <title>Event propagation in javascript</title>
      <dc:creator>Saran Chakravarthi</dc:creator>
      <pubDate>Wed, 11 May 2022 13:53:45 +0000</pubDate>
      <link>https://dev.to/saran_chakravarthi/event-propagation-in-javascript-36mi</link>
      <guid>https://dev.to/saran_chakravarthi/event-propagation-in-javascript-36mi</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Javascript events happen in three phases, namely, &lt;br&gt;
            1.the capturing phase, &lt;br&gt;
            2.the target phase and &lt;br&gt;
            3.the bubbling phase.&lt;/p&gt;

&lt;p&gt;Before understanding how event propagation works, let's understand why we have to understand event propagation. &lt;/p&gt;

&lt;p&gt;Sometimes, JavaScript event handlers may get invoked in unintended places. If we understand how event propagation occurs, we can avoid those kind of unintended event handling.&lt;/p&gt;

&lt;p&gt;Consider the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"main-section"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"main-btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;click me&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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;mainSection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;main-section&lt;/span&gt;&lt;span class="dl"&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;mainButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;main-btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;mainSection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Clicked main-section&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="nx"&gt;mainButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Clikced button&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have a div element with id &lt;code&gt;main-section&lt;/code&gt; , inside which we have a button with id &lt;code&gt;main-btn&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We are adding a click event listener to the div, which will print the string &lt;code&gt;Clicked main-section&lt;/code&gt; to the console. Similarly, we have a click event listener for the button as well, which will print the string &lt;code&gt;Clikced button&lt;/code&gt; to the console.&lt;/p&gt;

&lt;p&gt;Let's say we click the button, what will get printed on the console? &lt;/p&gt;

&lt;p&gt;If you guessed &lt;code&gt;Clikced button&lt;/code&gt;, you are wrong. It will print both &lt;code&gt;Clikced button&lt;/code&gt; and &lt;code&gt;Clicked main-section&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JZNG54mG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztssmu1cqa581qo2e9cl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JZNG54mG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztssmu1cqa581qo2e9cl.png" alt="Image description" width="386" height="95"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The event handler of button is invoked first and then the event handler of div is invoked. &lt;/p&gt;

&lt;h1&gt;
  
  
  The three phases
&lt;/h1&gt;

&lt;p&gt;Let's understand why. The event is not generated at the target element, where the event happened. Instead the event is generated at the root of the document (i.e, the top of the DOM tree)&lt;/p&gt;

&lt;p&gt;Then the event travels downwards, from the root to the target element. This phase is called the capturing phase. As it travels down, the event will be passed through every single parent of the target element.&lt;/p&gt;

&lt;p&gt;As soon as the event reaches the target, the event listener attached to the target element will start executing. This phase is called as the target phase.&lt;/p&gt;

&lt;p&gt;Once target phase is over, the event will travel all the way up to the root again, this phase is called as the bubbling phase. In bubbling phase,similar to capturing phase, the event will be passed through all the parents.&lt;/p&gt;

&lt;p&gt;We can notice that, in case of both capturing phase and bubbling phase, events are passed through the parents. It's like the event has happened in all these parent elements. Which means, if you have an event listener of same kind in one of the parent elements, that event listener will also be executed while performing the event on the target.&lt;/p&gt;

&lt;p&gt;By default, events can be handled in the target element, during the bubbling phase. This explains why the event handler of div is invoked after the event handler of the button.&lt;/p&gt;

&lt;p&gt;During the capturing phase, the event will travel from the root to the button and the target phase will take place, during which the event handler of the button will get invoked and &lt;code&gt;Clikced button&lt;/code&gt; will get printed to the console. And finally during the bubbling phase, the event will travel from the target to the root, through the button's parents. Since we have a click event listener on the main-section div, it will be invoked and the string &lt;code&gt;Clicked main-section&lt;/code&gt; will get printed to the console.&lt;/p&gt;

&lt;h1&gt;
  
  
  Event bubbling prevention
&lt;/h1&gt;

&lt;p&gt;Inorder to prevent the propagation of the event, you can invoke the &lt;code&gt;stopPropagation&lt;/code&gt; method of the event. If you invoke this method, the event propagation will stop then and there in the target itself, it will not travel up to the root. In other words, the bubbling phase will not take place.&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;mainButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&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="nx"&gt;event&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Clikced button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stopPropagation&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;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--brVJCJ9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3hg6t49tdsqoy5aji06.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--brVJCJ9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3hg6t49tdsqoy5aji06.png" alt="Image description" width="193" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>JavaScript Demystified:  Short-circuiting, nullish coalescing and Optional chaining</title>
      <dc:creator>Saran Chakravarthi</dc:creator>
      <pubDate>Wed, 12 Jan 2022 06:48:24 +0000</pubDate>
      <link>https://dev.to/saran_chakravarthi/javascript-demystified-short-circuiting-nullish-coalescing-and-optional-chaining-1e4n</link>
      <guid>https://dev.to/saran_chakravarthi/javascript-demystified-short-circuiting-nullish-coalescing-and-optional-chaining-1e4n</guid>
      <description>&lt;p&gt;Hello Devs! In this blog, I'll walk you through the concepts of logical operator, Short-circuiting, nullish coalescing and optional chaining in JavaScript.&lt;/p&gt;

&lt;h1&gt;
  
  
  Logical operators:
&lt;/h1&gt;

&lt;p&gt;It is essential to understand the working of logical operators inorder to understand short-circuiting.&lt;/p&gt;

&lt;p&gt;There are three logical operators in JavaScript: the AND operator, the OR operator and the NOT operator.&lt;/p&gt;

&lt;h2&gt;
  
  
  AND operator:
&lt;/h2&gt;

&lt;p&gt;AND operator will return true only if all the values are truthy, else it will return false.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hey&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  OR operator:
&lt;/h2&gt;

&lt;p&gt;OR operator returns true if atleast one of the values is true, else it will return false.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hey&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  NOT operator:
&lt;/h2&gt;

&lt;p&gt;The NOT operator will return true if used with a falsy value and it will return false if used with a truthy 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="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hey&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Out of these three operators, the AND operator and the OR operator can be short-circuited.&lt;/p&gt;

&lt;h1&gt;
  
  
  Short-circuiting:
&lt;/h1&gt;

&lt;p&gt;Short-circuiting can be defined as the phenomenon in programming by which the compiler or the interpreter skips the evaluation of the sub-expressions in an expression, as soon as it determines the final result of that expression.&lt;/p&gt;

&lt;h2&gt;
  
  
  AND operator:
&lt;/h2&gt;

&lt;p&gt;We know that the AND operator will return true only if all the values are true. So, it can safely return false, as soon as it encounters a falsy value. It does not have to check other values, because if one of the values is falsy, entire expression will turn out to be false.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 0;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here in this example, JavaScript will stop evaluating the expression as soon as it encounters the variable c. Because c is 0 , and 0 is a falsy value.&lt;/p&gt;

&lt;h2&gt;
  
  
  OR operator:
&lt;/h2&gt;

&lt;p&gt;The OR operator returns true if atleast one of the values is truthy. So, as soon as JavaScript encounters a truthy value, it can stop evaluating the expression.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//12;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, JavaScript will stop evaluating as soon as it encounters c, since it's a truthy value.&lt;/p&gt;

&lt;p&gt;Before es6, default parameters were not a thing. So programmers used "OR short-circuiting" to get things done.&lt;/p&gt;

&lt;p&gt;Let's say you are developing the backend for a bank. There are two types of accounts, zero balance account and normal account. The minimum balance for normal account is 1000, if that is the case, the customer can choose not to enter any value for deposit amount. In the backend, we can check if the deposit amount is present, if it is present, we can set it as the balance, if not, we can set 1000 as the balance. Sounds good?, let's implement this logic.&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;let&lt;/span&gt; &lt;span class="nx"&gt;dataBase&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;createAccount&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;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;depositAmount&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;newUser&lt;/span&gt; &lt;span class="o"&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;depositAmount&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;dataBase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newUser&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;newUser&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;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//{ name: 'Alice', id: 1, balance: 5000 }&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//{ name: 'Bob', id: 2, balance: 1000 }&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Joe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//{ name: 'Joe', id: 3, balance: 1000 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;uh-oh, seems like our logic isn't that good. Notice what happens when the value passed as depositAmount is 0(incase of zero balance account). 0 is a falsy value hence the balance will get assigned with 1000. Which is wrong and bad for your business. What if I tell you there's a way around it?&lt;/p&gt;

&lt;h1&gt;
  
  
  Nullish coalescing operator.
&lt;/h1&gt;

&lt;p&gt;The nullish coalescing(??) is very similar to the logical OR operator. The difference is nullish coalescing operator treats null and undefined as falsy values and everything else as truthy values.&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;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="c1"&gt;//John&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isVerified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isVerified&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in the bank account creation example, we could use nullish coalescing operator instead of the OR operator. Trust me, it would save your bank a ton of money.&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;let&lt;/span&gt; &lt;span class="nx"&gt;dataBase&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;createAccount&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;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;depositAmount&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;newUser&lt;/span&gt; &lt;span class="o"&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;depositAmount&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;dataBase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newUser&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;newUser&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;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//{ name: 'Alice', id: 1, balance: 5000 }&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//{ name: 'Bob', id: 2, balance: 1000 }&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Joe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//{ name: 'Joe', id: 3, balance: 0 }&lt;/span&gt;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  Optional chaining:
&lt;/h1&gt;

&lt;p&gt;Has it ever occurred to you, when you try to access a property of a variable you get the following error:&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="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Cannot&lt;/span&gt; &lt;span class="nx"&gt;read&lt;/span&gt; &lt;span class="nx"&gt;properties&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is because we did not receive the expected object, instead we received undefined. I know this error is annoying.&lt;/p&gt;

&lt;p&gt;The optional chaining operator checks whether the referenced object is nullish(null or undefined) or not. If it is nullish , it returns undefined. If not, it returns the actual value of that property.&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;person&lt;/span&gt; &lt;span class="o"&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="s2"&gt;Joe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&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="c1"&gt;//"Joe"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fav&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;food&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  connect with me:
&lt;/h2&gt;

&lt;p&gt;I hope you liked this blog. Want to connect? You can DM on Dev.to and &lt;a href="https://twitter.com/SaranChakravar3"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Introduction to cloud computing</title>
      <dc:creator>Saran Chakravarthi</dc:creator>
      <pubDate>Wed, 15 Sep 2021 18:37:47 +0000</pubDate>
      <link>https://dev.to/saran_chakravarthi/introduction-to-cloud-computing-hf4</link>
      <guid>https://dev.to/saran_chakravarthi/introduction-to-cloud-computing-hf4</guid>
      <description>&lt;h1&gt;
  
  
  Why cloud computing:
&lt;/h1&gt;

&lt;p&gt;Before understanding what cloud computing is, Let's understand why cloud computing was needed and what are all the problems we had that cloud computing solved.&lt;/p&gt;

&lt;p&gt;Before cloud computing, the business should buy a stack of servers for their use. They have to allot some space to place their servers. And then they have to hire people to monitor and maintain the servers. As the traffic increases, they have to buy more servers and hire more people to maintain the servers.&lt;/p&gt;

&lt;p&gt;Now, let's consider an e-commerce website. The business realizes that it would need 1000 more servers for the new year sale. It could go ahead and buy 1000 more servers and hire more people to maintain those servers. But most probably the traffic won't be that high after new year sales, which means some servers have to stay idle most of the times. So they end up paying a lot more than they use.&lt;/p&gt;

&lt;p&gt;The business needs someone who can provide 1000 servers whenever needed and take those servers away whenever not needed. Cloud exactly provides this.&lt;/p&gt;

&lt;p&gt;Cloud is a solution with dynamic way to scale up and scale down the services as required. Cloud signifies abstraction. It is built of many data centers. The user need not worry about maintenance or security, the cloud provider will take care of it. When you use cloud computing, you don't have to buy any servers, you can just rent servers for a time period. Hence, there is no principal expenditure. The users gain access to advanced features. Users can rent only the services they need. Cloud computing follows "pay as you use" model, you have to pay only for the services that you use.&lt;/p&gt;

&lt;p&gt;Now, the e-commerce business can rent 1000 more servers for a time period of three weeks. Pay as you use model and scalability makes cloud computing cost effective and agile.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is cloud computing
&lt;/h1&gt;

&lt;p&gt;Cloud computing is the on-demand availability of computer system resources, especially data storage (cloud storage) and computing power, without direct active management by the user. Large clouds often have functions distributed over multiple locations, each location being a data center. Cloud computing relies on sharing of resources to achieve coherence and economies of scale. Cloud providers typically use a pay as you use model, which can help in reducing capital expenses but may also lead to unexpected operating expenses for unaware users.&lt;/p&gt;

&lt;h1&gt;
  
  
  History of cloud computing
&lt;/h1&gt;

&lt;p&gt;Before cloud computing, there was client-server computing, which is a centralized storage in which all the data, applications and controls are stored in the server side. If a user wants to access a specific data or a software, the user needs to connect to the server.&lt;/p&gt;

&lt;p&gt;After this, distributed computing was introduced, in which computers are networked together and share the resources when needed. Cloud computing is based on the concept of distributed computing.&lt;/p&gt;

&lt;p&gt;In 1961, John MacCharty proposed the concept of utility computing. Utility computing suggests that computing can be sold like a utility, just like water or electricity.&lt;/p&gt;

&lt;p&gt;The launch of world wide web in the early 1990s had a huge impact on cloud computing. Millions of computers were connected to the internet which led to the dot com revolution and e-commerce gaining popularity. As a result, businesses like salesforce.com were born. Salesforce was the first company to offer application as a service over internet, Salesforce pioneered the concept of delivering enterprise app through a simple app.&lt;/p&gt;

&lt;p&gt;Three years later, in 2002 Amazon launch Amazon Web services (AWS), it provided services like storage, computation and even human intelligence. Few years later in 2006, Amazon introduced new services like Amazon simple storage service (Amazon S3), Amazon elastic compute cloud (Amazon EC2). These services helped companies and individuals to rent virtual computers and run their own programs and applications on the virtual computer(s) through internet. Later that year, Google launched Google docs services.&lt;/p&gt;

&lt;p&gt;In 2009, Google apps started to provide cloud computing services to enterprise applications. Microsoft entered the world of cloud by launching Microsoft Azure.&lt;/p&gt;

&lt;p&gt;Now, the end users are familiar with the concept of cloud. They happily store their data in remote storage location provided by a cloud storage service provider.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is a cloud service?
&lt;/h1&gt;

&lt;p&gt;The term "cloud services" refers to a wide range of services delivered on demand to companies and customers over the internet. These services are designed to provide easy, affordable access to applications and resources, without the need for internal infrastructure or hardware. From checking email to collaborating on documents, most employees use cloud services throughout the workday, whether they’re aware of it or not.&lt;/p&gt;

&lt;p&gt;The aim is to fullfil an customer's needs. A customer might have 10 needs, the aim of a cloud service provider is to meet all 10 needs. The service provider can carry out either customized approach or packaged approach to fullfil the customer's needs.&lt;/p&gt;

&lt;h1&gt;
  
  
  How do cloud services work?
&lt;/h1&gt;

&lt;p&gt;Cloud services are fully managed by cloud computing vendors and service providers. They are made available to customers from the providers' servers, so there's no need for a company to host the applications on its own on-premises servers.&lt;/p&gt;

&lt;h1&gt;
  
  
  Types of cloud service models:
&lt;/h1&gt;

&lt;p&gt;Cloud services can be broadly classified into three types of service models:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;SaaS&lt;/li&gt;
&lt;li&gt;IaaS&lt;/li&gt;
&lt;li&gt;PaaS&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  SaaS
&lt;/h2&gt;

&lt;p&gt;SaaS stands for software as a service. It is the most common use case of the cloud services. SaaS allows users to connect to and use cloud based applications over the internet. The software actually runs at the cloud service provider's data center on their physical servers. Even the data captures is stored in the service provider's data center. Everything is managed for us by the cloud service provider, we simply access the software over the internet. &lt;/p&gt;

&lt;p&gt;Consider Gmail, the user is only concerned about using the application properly. The user need not worry about things like how the message gets delivered, what if the server goes down, what are the security concerns, what's happening in the background. Gmail is a good example of Saas.&lt;/p&gt;

&lt;p&gt;Eg: office 365, Netflix, Amazon prime, Dropbox, Google drive.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Easy to get started&lt;/li&gt;
&lt;li&gt;Accessibility&lt;/li&gt;
&lt;li&gt;Automatic updates&lt;/li&gt;
&lt;li&gt;Flexible usage based pricing&lt;/li&gt;
&lt;li&gt;Reduced financial risk&lt;/li&gt;
&lt;li&gt;Affordable&lt;/li&gt;
&lt;li&gt;No maintenance cost as it does not require any additional hardware or software versions.&lt;/li&gt;
&lt;li&gt;Scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Insufficient data security&lt;/li&gt;
&lt;li&gt;Troublesome software integration&lt;/li&gt;
&lt;li&gt;Once an enterprise becomes dependent on a SaaS application, it will be difficult to switch from one vendor to another.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  PaaS
&lt;/h2&gt;

&lt;p&gt;PaaS stands for platform as a service. PaaS is a programming platform for developers. This platform is generated for the programmers to create, test, run and manage the applications.&lt;br&gt;
A developer can easily write the application and deploy it directly into PaaS layer.&lt;br&gt;
PaaS gives the runtime environment for application development and deployment tools.&lt;br&gt;
Server and virtual machines are provided and maintained by the cloud service provider. No need to handle backups as its also handled by the cloud service provider.&lt;/p&gt;

&lt;p&gt;eg:Google Apps Engine(GAE), Windows Azure, SalesForce.com, Amazon Web Services(AWS), IBM Blue mix&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;simplified development&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;lower price&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integrates with web services and databases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Accessible to various users via the same development application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Instant community support&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Builds on virtualization technology, so resources can easily be scaled up or down as per the organization's need.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Developer only requires a PC and an Internet connection to start building applications.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Security risks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Developer can write the applications as per the platform provided by PaaS vendor hence the moving the application to another PaaS vendor is a problem.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  IaaS
&lt;/h2&gt;

&lt;p&gt;IaaS stands for infrastructure as a service. In IaaS, you buy complete resources rather than purchasing server, software, network equipments individually. The customers can access these resources through cloud computing service provider platform. The customer need not worry about the principal expenditure of setting up the servers or maintenance, as they are taken care of by the cloud service provider.&lt;/p&gt;

&lt;p&gt;Eg: digital ocean,  Cisco meta cloud, linode, Google Compute Engine (GCE)&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The customer doesn't have to worry about principal expenditure or maintenance cost.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enhanced scalability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Support for dynamic workload&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Users can choose a CPU, memory storage according to their needs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automated administrative tasks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Flexible&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Limited customisation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security risks: IaaS providers secure the infrastructure, but businesses are responsible for anything they host.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Technical issues: downtime is one of the most common technical issues faced while using IaaS solution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Changing vendors can be difficult&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Cloud deployment model:
&lt;/h1&gt;

&lt;p&gt;A cloud deployment model is a specific configuration of environment parameters such as the accessibility and proprietorship of the deployment infrastructure and storage size. This means that deployment types vary depending on who controls the infrastructure and where it’s located. Broadly, it can be classified into 4 types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Public cloud&lt;/li&gt;
&lt;li&gt;Private cloud&lt;/li&gt;
&lt;li&gt;Community cloud and&lt;/li&gt;
&lt;li&gt;Hybrid cloud&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Public cloud
&lt;/h2&gt;

&lt;p&gt;A public cloud is available for use, for anyone. If an individual subscribes to a public cloud service, the cloud service will provide services to that individual. It allows the system and services to be easily available to the general public.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;p&gt;1.Low cost&lt;br&gt;
2.Higly scalable&lt;br&gt;
3.Flexible&lt;br&gt;
4.No hardware setup&lt;br&gt;
5.No infrastructure management&lt;/p&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Reliability issues&lt;/li&gt;
&lt;li&gt;Data security and privacy concerns&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Private cloud:
&lt;/h2&gt;

&lt;p&gt;Unlike public clouds, a private clouds are owned by a single company. Hence, it is also known as internal model or. Corporate model.&lt;/p&gt;

&lt;p&gt;The server can be hosted on the premises of the owner company or externally. Either way, the servers are to be maintained by the owner company.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Highly private &lt;/li&gt;
&lt;li&gt;Secure&lt;/li&gt;
&lt;li&gt;Control oriented&lt;/li&gt;
&lt;li&gt;Private model can support legacy systems that cannot access the public clouds&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;High capital expenditure.&lt;/li&gt;
&lt;li&gt;Fixed scalability&lt;/li&gt;
&lt;li&gt;High maintenance cost.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Community cloud:
&lt;/h2&gt;

&lt;p&gt;In community cloud model, only one company owns and maintains the cloud servers. But the cloud infrastructure is shared among different organizations with similar background. Access to a community cloud environment is typically restricted to the members of the community.  An example of such a community is where organizations/firms are there, along with the financial institutions/banks. A multi-tenant setup developed using cloud among different organizations that belong to a particular community or group having similar computing concerns.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Cost reduction&lt;/li&gt;
&lt;li&gt;Collaboration&lt;/li&gt;
&lt;li&gt;Security and reliability&lt;/li&gt;
&lt;li&gt;Ease of data sharing&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Disadvantages:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Increased maintenance cost&lt;/li&gt;
&lt;li&gt;Remote access may be limited&lt;/li&gt;
&lt;li&gt;Have to hire more IT staffs&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Hybrid cloud model:
&lt;/h2&gt;

&lt;p&gt;As the name suggests, hybrid cloud model is a combination of two of more cloud models combined as one architecture. Hybrid model will have the advantages of all the models involved in it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Flexible&lt;/li&gt;
&lt;li&gt;Can be customized for a company's need.&lt;/li&gt;
&lt;li&gt;Unique balance of control and performance&lt;/li&gt;
&lt;li&gt;Quick deployment&lt;/li&gt;
&lt;li&gt;Scalability&lt;/li&gt;
&lt;li&gt;Low cost&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Compatibility&lt;/li&gt;
&lt;li&gt;Security&lt;/li&gt;
&lt;li&gt;Networking bottlenecks&lt;/li&gt;
&lt;li&gt;Maintaining visibility over a hybrid cloud service is complicated&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Features of cloud computing:
&lt;/h2&gt;

&lt;p&gt;Let's look at the most important features of cloud computing.&lt;/p&gt;

&lt;h3&gt;
  
  
  On demand self service:
&lt;/h3&gt;

&lt;p&gt;This is a fundamental characteristic of cloud computing. The cloud computing services does not require much human interaction from the service provider. The user can provision, monitor and manage the resources as needed. &lt;/p&gt;

&lt;h3&gt;
  
  
  Resources pooling:
&lt;/h3&gt;

&lt;p&gt;The cloud service provider can share the computing resources (like storage,network,server) among the users as per the individual's needs. In other words, the cloud service provider's resources are pooled to multiple customers using a multi-tenant model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scalability and rapid elasticity:
&lt;/h3&gt;

&lt;p&gt;Resources can be elastically provisioned and released to meet immediate requirements. And the resources can be scaled in and scaled out as needed. This enables cost effective running of workloads that require large number of servers but only for a short period of time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Economical:
&lt;/h3&gt;

&lt;p&gt;The user has to pay only for the services used. There are no hidden charges.&lt;/p&gt;

&lt;h3&gt;
  
  
  Measured services:
&lt;/h3&gt;

&lt;p&gt;The resource consumption is measured and reported for each service. This gives transparency to both the service provider and the consumer. This helps the user understand the effective use of resource.&lt;/p&gt;

&lt;h3&gt;
  
  
  Security:
&lt;/h3&gt;

&lt;p&gt;Security is one of the most important features of cloud computing. The cloud service provider creates a copy of the data, so that even if the data gets lost by any chance, the copy version can be restored.&lt;/p&gt;

&lt;h3&gt;
  
  
  Broad network access:
&lt;/h3&gt;

&lt;p&gt;Cloud computing services are generally accessible from anywhere over the internet. And incase of private clouds, services can be accessed from anywhere within the enterprise. The services can be accessed on a variety of platforms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Maintenance:
&lt;/h3&gt;

&lt;p&gt;The servers are maintained by the cloud service provider. The downtime is generally very low and in some cases, there is no downtime at all.&lt;/p&gt;

&lt;h1&gt;
  
  
  Challenges
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Lack of expertise
&lt;/h2&gt;

&lt;p&gt;With the increasing workload on cloud technologies and continuously improving cloud tools, the management has become difficult. There has been a consistent demand for a trained workforce who can deal with cloud computing tools and services. Hence, firms need to train their IT staff to minimize this challenge.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Cloud Cost Management:
&lt;/h2&gt;

&lt;p&gt;Cloud computing enables you to access application software over a fast internet connection and lets you save on investing in costly computer hardware, software, management and maintenance. This makes it affordable. But what is challenging and expensive is tuning the organization’s needs on the third-party platform. &lt;/p&gt;

&lt;p&gt;Another costly affair is the cost of transferring data to a public cloud, especially for a small business or project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloud Migration:
&lt;/h2&gt;

&lt;p&gt;It is easier to migrate a new application from one cloud service provider to another. Once application becomes dependent on a cloud service provider, it will be fairly difficult to move to a new cloud service provider.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compliance:
&lt;/h2&gt;

&lt;p&gt;Compliance means a set of rules about what data is allowed to be moved and what should be kept in-house. The organizations must follow and respect the compliance rules set by various government bodies. Whenever an organization transfers data from its internal storage to the cloud, it experiences compliance with the laws and regulations of the industry.&lt;/p&gt;

&lt;h2&gt;
  
  
  performance
&lt;/h2&gt;

&lt;p&gt;When your business applications move to a cloud or a third party vendor, your business performance starts to depend on your provider as well. Another major problem in cloud computing is investing in the right cloud service provider.&lt;/p&gt;

&lt;h2&gt;
  
  
  internet connectivity
&lt;/h2&gt;

&lt;p&gt;The cloud services are dependent on a high-speed internet connection. So the businesses that are relatively small and face connectivity issues should ideally first invest in a good internet connection so that no downtime happens. It is because internet downtime might incur vast business losses.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Demystified: Hoisting</title>
      <dc:creator>Saran Chakravarthi</dc:creator>
      <pubDate>Tue, 20 Jul 2021 11:09:30 +0000</pubDate>
      <link>https://dev.to/saran_chakravarthi/javascript-demystified-hoisting-21bf</link>
      <guid>https://dev.to/saran_chakravarthi/javascript-demystified-hoisting-21bf</guid>
      <description>&lt;p&gt;Hello Devs! In this blog, I'll walk you through the concept of hoisting in JavaScript. Before we begin, go through the first blog of this blog series, if you haven't already.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is hoisting
&lt;/h2&gt;

&lt;p&gt;Hoisting is a phenomenon in JavaScript by which you can access the functions and variables even before declaring them in your program, without getting an error.&lt;/p&gt;

&lt;p&gt;Let's see it with an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
var x = 10;

function greet(){
  console.log("Hello world!");
}

console.log(x);

greet();

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

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
10
Hello world!

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

&lt;/div&gt;



&lt;p&gt;The above program is pretty simple and straightforward. Let's see what happens when we try to access the variable and the function before declaring them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
console.log(x);

greet();

var x = 10;

function greet(){
  console.log("Hello world!");
}

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

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
undefined
Hello world!

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

&lt;/div&gt;



&lt;p&gt;If you have read the &lt;a href="https://dev.to/saran_chakravarthi/javascript-demystified-the-execution-context-and-the-call-stack-2gka"&gt;first blog&lt;/a&gt;, you already know why this is happening. whenever we run a program, an execution context is created, and it is executed in two phases, the memory allocation phase and the code execution phase.&lt;/p&gt;

&lt;p&gt;During the memory allocation phase, memory will be allocated for variable X and it will be assigned with the value "undefined", similar memory will be allocated for the function greet and it will be assigned with the original function definition.&lt;/p&gt;

&lt;p&gt;The value of X will be undefined, until and unless we reach the variable assignment of X , during the code execution phase. &lt;/p&gt;

&lt;p&gt;In the second example, we are trying to access the variable even before assigning it with a value, that's why it's value is printed as undefined.&lt;/p&gt;

&lt;h3&gt;
  
  
  Undefined Vs not defined:
&lt;/h3&gt;

&lt;p&gt;Undefined and not defined, are they the same? No. As we seen in the last blog, undefined is kind of a special placeholder keyword.&lt;/p&gt;

&lt;p&gt;Not defined is an error, which is thrown when you try to access a variable which is nowhere declared in your program.&lt;/p&gt;

&lt;h3&gt;
  
  
  Arrow functions and function expression:
&lt;/h3&gt;

&lt;p&gt;If you try to access Arrow functions and function expression before declaring them in your program, it will throw an error saying "Typeerror".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
greet();

var greet = function(){
  console.log("Hello world!");
}

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
greet();

var greet = () =&amp;gt; {
  console.log("Hello world!");
}

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

&lt;/div&gt;



&lt;p&gt;If you try to run either of the above code snippets, it will result in the following error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
TypeError: greet is not a function

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

&lt;/div&gt;



&lt;p&gt;Why? Because in this case, the function is assigned to a variable, so it's value is stored as "undefined". Hence the error.&lt;/p&gt;

&lt;p&gt;Note: let and const variables will behave differently from var, it will be covered in the upcoming blogs.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's next:
&lt;/h3&gt;

&lt;p&gt;I hope you liked this blog, In the next blog, we will dive deep into functions and variable environment. Follow me to receive the notification.&lt;/p&gt;

&lt;p&gt;Want to connect with me? You can DM on Dev.to and &lt;a href="https://twitter.com/SaranChakravar3"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Demystified: The execution context and the call stack</title>
      <dc:creator>Saran Chakravarthi</dc:creator>
      <pubDate>Fri, 16 Jul 2021 21:02:01 +0000</pubDate>
      <link>https://dev.to/saran_chakravarthi/javascript-demystified-the-execution-context-and-the-call-stack-2gka</link>
      <guid>https://dev.to/saran_chakravarthi/javascript-demystified-the-execution-context-and-the-call-stack-2gka</guid>
      <description>&lt;p&gt;Hello Devs, "JavaScript demystified" is going to be a series of blogs. And this is the first one. I will try to cover the important yet not well-known javascript concepts in this blog series. I would like to start off the series by explaining the execution context and the call stack.&lt;/p&gt;

&lt;h1&gt;
  
  
  Execution context:
&lt;/h1&gt;

&lt;p&gt;Execution context may be defined as the environment in which the code gets executed. Everything in JavaScript happens inside the execution context&lt;/p&gt;

&lt;p&gt;It is composed of two components, the memory component and the code component.&lt;/p&gt;

&lt;h2&gt;
  
  
  The memory component:
&lt;/h2&gt;

&lt;p&gt;The memory component, also known as the variable environment, stores the variable, functions and their values as key-value pairs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The code component:
&lt;/h2&gt;

&lt;p&gt;It is also known as the thread of execution. Inside the code component, the code is executed one line at a time.&lt;/p&gt;

&lt;p&gt;Execution context is created in two phases. The first one is memory creation phase, in this phase the interpreter skims through the whole program and allocates memory to the variables and functions. The second phase is called the code execution phase, the code gets executed in this phase.&lt;/p&gt;

&lt;p&gt;Let's visualize this with an example. Consider the following program:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var n = 10;

function double(num){
    return num*2;
}

a = double(n);
b = double(7);

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

&lt;/div&gt;



&lt;p&gt;When the program starts to execute, a new execution context will be created, since we are dealing with global level, it is called the global execution context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory allocation phase:
&lt;/h2&gt;

&lt;p&gt;On line number one, memory is allocated for the variable n, and it is assigned with the value "undefined". You can think of "undefined" as a special placeholder keyword (we will learn more about it in the upcoming blogs).&lt;/p&gt;

&lt;p&gt;Then memory is allocated for double function, the whole function is assigned to it as its value.&lt;/p&gt;

&lt;p&gt;Similar to variable n, memory is allocated for variables a and b, and they are assigned with the value "undefined"&lt;/p&gt;

&lt;p&gt;This is how the execution context will look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VlT1368u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvmsxu55hhbhyys1484o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VlT1368u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvmsxu55hhbhyys1484o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code execution phase:
&lt;/h2&gt;

&lt;p&gt;Code is executed line by line, firstly the value of n will be replaced with 10. The function definition of double will be skipped, as it is just a definition, there is nothing to be executed. Then we reach the function invocation where double function is called. Now something interesting happens, a new execution context will be created inside the global execution context's thread of execution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AJIp3rRv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pm6hq99nrdjam6ecel0o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AJIp3rRv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pm6hq99nrdjam6ecel0o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The same process will happen to this new execution context as well.&lt;/p&gt;

&lt;p&gt;During the memory creation phase, memory will be allocated for num and will be assigned with undefined.&lt;/p&gt;

&lt;p&gt;During the code execution phase the value of num will be replaced by 10. &lt;/p&gt;

&lt;p&gt;When the program reaches "return" keyword, the control is returned to the function caller, along with value specified after the return keyword.  Then that particular execution context is deleted. In our case, execution context of &lt;code&gt;double(n)&lt;/code&gt; will be deleted.&lt;/p&gt;

&lt;p&gt;similarly &lt;code&gt;double(7)&lt;/code&gt; will also be executed.&lt;/p&gt;

&lt;p&gt;Once the program reaches the end of the file, the global execution context will also be deleted.&lt;/p&gt;

&lt;h1&gt;
  
  
  The call stack:
&lt;/h1&gt;

&lt;p&gt;The example we saw was pretty simple. But what if we have multiple function invocations inside a function, how will JavaScript handle it? The answer is call stack.&lt;/p&gt;

&lt;p&gt;It is similar to the stack data structure. It follows the LIFO(Last In First Out) principle.&lt;/p&gt;

&lt;p&gt;Whenever we start a program, the global execution context is pushed into the stack. After that if we call a function it is pushed into the stack. Once the code reaches the return statement, the function gets popped off the stack. The global execution context will be popped off when we reach the end of the file.&lt;/p&gt;

&lt;p&gt;As we saw, JavaScript has only one call stack, hence it is &lt;strong&gt;single threaded&lt;/strong&gt;. And it executes the code line by line, so it is &lt;strong&gt;synchronous&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But you might say, "I have used AJAX, JavaScript is asynchronous". No, JavaScript is not asynchronous. We will see how javascript handles asynchronous code in the upcoming blogs.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's next:
&lt;/h3&gt;

&lt;p&gt;I hope you liked this blog, In the next blog, I will cover the concept of hoisting. Follow me to receive the notification.&lt;/p&gt;

&lt;p&gt;Want to connect with me? You can DM on Dev.to and &lt;a href="https://twitter.com/SaranChakravar3"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Stateful architecture Vs stateless architecture</title>
      <dc:creator>Saran Chakravarthi</dc:creator>
      <pubDate>Fri, 16 Jul 2021 09:44:18 +0000</pubDate>
      <link>https://dev.to/saran_chakravarthi/stateful-architecture-vs-stateless-architecture-2dh8</link>
      <guid>https://dev.to/saran_chakravarthi/stateful-architecture-vs-stateless-architecture-2dh8</guid>
      <description>&lt;p&gt;Let's say we have developed an application. For the sake of simplicity, let's assume that we have only two pages, login page and user profile page.&lt;/p&gt;

&lt;p&gt;We should display the profile of the user only when they are logged in. Let's see how stateful application and stateless application handles this. &lt;/p&gt;

&lt;h2&gt;
  
  
  Stateful:
&lt;/h2&gt;

&lt;p&gt;If we choose to use stateful architecture, we will have to store the state of the user(s) somehow. Usually the state is stored in the server itself. &lt;/p&gt;

&lt;p&gt;But what if the server goes down? Since we store the state in the memory of the server, we could possibly lose all the stored states. It's hard to restore the state.&lt;/p&gt;

&lt;p&gt;On the upside, we don't have to query the database everytime we receive a request, to check if the user is logged in or not.&lt;/p&gt;

&lt;p&gt;What if we decide to have more than one server?, Let's say the user logs in by sending a request to server-1 and the state is stored in server-1. Now the user is trying to access their profile page, due to high traffic the request is directed to server-2. Remember, the state is stored in the memory of server-1 only, so according to server-2, the user is not logged in. This might lead to inconsistency. Hence, stateful application might not go well with &lt;a href="https://dev.to/saran_chakravarthi/horizontal-vs-vertical-scaling-2h1h"&gt;horizontal scaling&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;p&gt;No need to query the database.&lt;/p&gt;

&lt;p&gt;It is quick, as we don't have to query the database everytime.&lt;/p&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;p&gt;If the server goes down, it will be hard to recover.&lt;/p&gt;

&lt;p&gt;We can't scale up horizontally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stateless:
&lt;/h2&gt;

&lt;p&gt;In case of a stateless architecture, a token is sent back to the client, when the user logs in. This token is stored in client's storage. Then this token is sent along with every request the user makes.&lt;/p&gt;

&lt;p&gt;Inorder to make sure that the request is coming from an authenticated user, we check the token sent along with the request, against the data we stored in the database.&lt;/p&gt;

&lt;p&gt;Since the token is stored in client's storage, we can easily recover if the server goes down. And horizontal scaling is much easier in stateless architecture.&lt;/p&gt;

&lt;p&gt;But the catch here is, we have to query the database everytime we get a request.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Horizontal scaling is easy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can easily recover if our sever goes down.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We have to query our database, for every request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Slower than stateful architecture.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this article helped you. Want to connect with me? my DM is open on dev.to, you can connect with me on &lt;a href="https://twitter.com/SaranChakravar3"&gt;twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>design</category>
      <category>architecture</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Horizontal scaling Vs vertical scaling</title>
      <dc:creator>Saran Chakravarthi</dc:creator>
      <pubDate>Wed, 14 Jul 2021 18:12:19 +0000</pubDate>
      <link>https://dev.to/saran_chakravarthi/horizontal-vs-vertical-scaling-2h1h</link>
      <guid>https://dev.to/saran_chakravarthi/horizontal-vs-vertical-scaling-2h1h</guid>
      <description>&lt;p&gt;Hello Devs, in this article I'll walk you through the differences between horizontal and vertical scaling.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is scaling?
&lt;/h1&gt;

&lt;p&gt;Let's say, you have developed an application and it is gradually getting traction. The user base is growing and the users are loving your app. Great!&lt;/p&gt;

&lt;p&gt;The user base has grownup to a point where your system can't handle that much load. Not so cool. You don't want to disappoint your users, do you? You'll probably try to upgrade your system so that it can handle heavy load. You have two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Buying more machines&lt;/li&gt;
&lt;li&gt;Buying a bigger machine&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There you have it. Scaling may be defined as the process upgrading your existing system to handle more load.&lt;/p&gt;

&lt;h2&gt;
  
  
  Horizontal scaling:
&lt;/h2&gt;

&lt;p&gt;It is the process of buying more machines.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hmm.. if we have more than one machine, how do we make sure that the load is spread equally among the machines?&lt;/em&gt; That's where load balancers come into play. Load balancers make sure that the traffic is distributed equally among the servers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Since we can buy as many machines as we want, we can say that horizontal scale scales well as the users increase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Even if one of the servers goes down, other working servers can handle the request. Hence it is resilient.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Load balancing is required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Servers communicate with eachother through network calls.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As we use more than one machine, it may lead to data inconsistency.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Vertical scaling:
&lt;/h2&gt;

&lt;p&gt;It is the process of buying a bigger machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Load balancer is not required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We use only one machine, hence the data is consistent.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The communication happens through interprocess communication, no network calls needed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Single point of failure. Since we have only one machine, if it goes down the entire system will stop working.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Eventually we will reach the hardware limit.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading! I hope this article helped you. Want to connect with me? my DM is open on dev.to, you can connect with me on &lt;a href="https://twitter.com/SaranChakravar3"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>beginners</category>
      <category>distributedsystems</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Bracket notation Vs dot notation in JavaScript objects</title>
      <dc:creator>Saran Chakravarthi</dc:creator>
      <pubDate>Tue, 13 Jul 2021 20:38:09 +0000</pubDate>
      <link>https://dev.to/saran_chakravarthi/bracket-notation-vs-dot-notation-in-javascript-objects-1hpo</link>
      <guid>https://dev.to/saran_chakravarthi/bracket-notation-vs-dot-notation-in-javascript-objects-1hpo</guid>
      <description>&lt;p&gt;Hello Devs, in this article, I will walk you through the differences between using dot notation and bracket notation in JavaScript objects.&lt;/p&gt;

&lt;p&gt;Consider the following object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let animalsList = {
  cow:{
    legs: 4,
    sound: "moo",
  },
  cat:{
    legs: 4,
    sound: "meow",
  },
};

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

&lt;/div&gt;



&lt;p&gt;We can use both dot and bracket notation to access the properties. Make sure that you enclose the key within quotes, when you use bracket notation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
console.log(animalsList.cat); //{ legs: 4, sound: 'meow' }
console.log(animalsList["cat"]); //{ legs: 4, sound: 'meow' }

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

&lt;/div&gt;



&lt;p&gt;As you can see, dot notation has better readability, it is an advantage of using dot notation.&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;So, if we can use both dot notation and bracket notation to access object properties, and dot notation has better readability, why do we even have bracket notation?&lt;/em&gt;", you might ask.&lt;/p&gt;

&lt;p&gt;Let's say we have a function, and the key which we have to access is passed to the function as an argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function myFun(animal){
  console.log(animalsList.animal);
}

myFun("cow"); 

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

&lt;/div&gt;



&lt;p&gt;The above code will print &lt;code&gt;undefined&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;When we use dot notation, JavaScript searches for the key with the exact name we used after the dot( animal, in our case). Since the animalsList doesn't have a property called "animal", undefined is printed.&lt;/p&gt;

&lt;p&gt;Let's try bracket notation instead of dot notation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function myFun(animal){
  console.log(animalsList[animal]);
}

myFun("cow");

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

&lt;/div&gt;



&lt;p&gt;The above code will work fine and print &lt;code&gt;{ legs: 4, sound: 'moo' }&lt;/code&gt;, as "animal" will be replaced with the respective argument which was passed during function call.&lt;/p&gt;

&lt;p&gt;To summarize, use bracket notation when you want to access property using variable, otherwise stick with dot notation.&lt;/p&gt;

&lt;p&gt;I hope this article helped you. Want to connect with me? my DM is open on dev.to, you can connect with me on &lt;a href="https://twitter.com/SaranChakravar3"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

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

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to architecture state variables in React</title>
      <dc:creator>Saran Chakravarthi</dc:creator>
      <pubDate>Tue, 13 Jul 2021 11:57:49 +0000</pubDate>
      <link>https://dev.to/saran_chakravarthi/how-to-architecture-state-variables-in-react-42h2</link>
      <guid>https://dev.to/saran_chakravarthi/how-to-architecture-state-variables-in-react-42h2</guid>
      <description>&lt;p&gt;Hello Devs, in this article, we will see how to architecture the state variables in your react app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If a state is used by a single component it should be inside that component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a state is used by multiple components in a tree and they are all direct children of the same parent component, it should be in their parent component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a state is used by multiple components in a tree but they are not direct children of the same parent component, it should be in context/redux.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a state is used by multiple components in different trees, it should be in context/redux.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this article helped you. Want to connect with me? my DM is open on dev.to, you can connect with me on &lt;a href="https://twitter.com/SaranChakravar3"&gt;twitter&lt;/a&gt;&lt;/p&gt;

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

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
