<?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: Chaitanya</title>
    <description>The latest articles on DEV Community by Chaitanya (@bmchaitu).</description>
    <link>https://dev.to/bmchaitu</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%2F204257%2F6cb6791d-e8a9-483b-9363-ba09be5d049c.jpg</url>
      <title>DEV Community: Chaitanya</title>
      <link>https://dev.to/bmchaitu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bmchaitu"/>
    <language>en</language>
    <item>
      <title>React Element vs React Component</title>
      <dc:creator>Chaitanya</dc:creator>
      <pubDate>Sat, 25 Jun 2022 04:33:21 +0000</pubDate>
      <link>https://dev.to/bmchaitu/react-element-vs-react-component-330i</link>
      <guid>https://dev.to/bmchaitu/react-element-vs-react-component-330i</guid>
      <description>&lt;p&gt;Hey there,&lt;/p&gt;

&lt;p&gt;Most of the developers would be using the React in their projects, but we often ignore the small things that sometimes may need to have a deep insight to understand.&lt;/p&gt;

&lt;p&gt;One of the such concepts for React is &lt;strong&gt;React Elements, and Component&lt;/strong&gt; differences.&lt;/p&gt;

&lt;p&gt;Let us see the differences between them:&lt;/p&gt;

&lt;h2&gt;
  
  
  React Element:
&lt;/h2&gt;

&lt;p&gt;React Element is an object which has the information about the type of react element, and the props that, it can hold and the children.&lt;/p&gt;

&lt;p&gt;let us say we have an react element whose tag is 'h1', and the text between the tag would be "Hello world". In this scenario the React element which is said an object earlier  would be represented as below:&lt;/p&gt;

&lt;p&gt;This is the representation would be stored in the react tree&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const reactElement = {
 type: 'h1',
 null,
 'Hello world',
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create that react element we would use createElement API of react as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React.createElement('h1', null, 'Hello world');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and same can be created using JSX:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello world&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let us say we have to create the same above element multiple places and we have such multiple usages. In such case we can create the function and keep the JSX in that function. so whenever we need we can call that function to have the same element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const renderElement = text =&amp;gt; {
  return (
     &amp;lt;h1&amp;gt;
       {text}
     &amp;lt;/h1&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;since the above function returns the JSX we can call that function whenever we need in JSX&lt;/p&gt;

&lt;p&gt;the usage of that function would be as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{renderElement("text1")}
{renderElement("text2)}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can also pass the &lt;code&gt;renderElement&lt;/code&gt; function to the createElement API to create reactElements&lt;/p&gt;

&lt;p&gt;React.createElement(renderElemet, null, 'Hello world');&lt;/p&gt;

&lt;p&gt;But what we cannot do with the renderElement function is we cannot use the &lt;strong&gt;renderElement&lt;/strong&gt; as tag which we did for &lt;strong&gt;div&lt;/strong&gt; tag as shown below:&lt;/p&gt;

&lt;p&gt;for a div tag you could have done this&lt;/p&gt;

&lt;p&gt;Vanilla JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const element1 = React.createElement('div', null, 'Helloworld');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JSX&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;const element2 = React.createElement(renderElement, null, 'Hello World');&lt;/p&gt;

&lt;p&gt;but you cannot use the element as JSX&lt;/p&gt;

&lt;p&gt;In order to use that function as tag, the name should be start with capital letter, and such functions are called components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const CustomComponent = ({ children }) =&amp;gt; {
return (
 &amp;lt;h1&amp;gt;
   {children}
&amp;lt;/h1&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this CustomComponent can be used as tag, or also rendered with React API as shown below:&lt;/p&gt;

&lt;p&gt;Vanilla JS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const element3 = React.createElement(CustomComponent, null, 'Hello world');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;CustomComponent&amp;gt;
  &amp;lt;h1&amp;gt;
   Hello world
  &amp;lt;/h1&amp;gt;
&amp;lt;/CustomComponent&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These Components also have access to the special variables within the scope of the Class, and functions called state which holds the values and the React elements can be re-rendered whenever these values are updated.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Big-Oh(O) does not give you always the worst-case, But why?</title>
      <dc:creator>Chaitanya</dc:creator>
      <pubDate>Mon, 22 Mar 2021 11:23:42 +0000</pubDate>
      <link>https://dev.to/bmchaitu/big-oh-o-does-not-give-you-always-the-worst-case-but-why-1e1</link>
      <guid>https://dev.to/bmchaitu/big-oh-o-does-not-give-you-always-the-worst-case-but-why-1e1</guid>
      <description>&lt;p&gt;The running time complexity of an algorithm is given by the run-time function of that algorithm. All the run-time functions are expressed in terms of mathematical functions. sometimes these run-time functions are compared with the standard mathematical functions like exponential functions, quadratic functions, and more. The input variables of the function are compared to inputs of the algorithm and the running time of the algorithm is the output of the mathematical functions. This comparison gives an understanding of the variation of the out with the change in the input variables which is an analogy to the change in the run-time of the algorithm with the change in the input size. Formally this comparison and analysis of the functions are called asymptotic analysis of an algorithm. The well known asymptotic notations are as below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Big-Oh&lt;/li&gt;
&lt;li&gt;Theta &lt;/li&gt;
&lt;li&gt;Omega&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All these asymptotic analyses give you the order in which the growth of the function depends on a change in the input of the function. The growth of the functions is considered and compared with the slopes and the manner how they grow. All these functions use auxiliary variables to give you a generic description and definition.&lt;/p&gt;

&lt;h3&gt;
  
  
  Big-Oh
&lt;/h3&gt;

&lt;p&gt;The Big-oh notation is defined as the upper bound of the given run-time function of the algorithm. This Big-Oh notation gives the functions which have a higher growth rate than the calculated run-time function where the starting input condition is given n0 or upper bound functions.&lt;br&gt;
Mathematically the Big-Oh notation is given as below:&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;O(g(n))={f(n):0≤f(n)≤c∗g(n),∀n≥n0}
 O(g(n)) = \lbrace f(n): 0\leq f(n) \leq c*g(n), \forall n \geq n0\rbrace
&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;O&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;g&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;))&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;{&lt;/span&gt;&lt;span class="mord mathnormal"&gt;f&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;:&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≤&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;f&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≤&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;c&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∗&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;g&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;∀&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≥&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord"&gt;0&lt;/span&gt;&lt;span class="mclose"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;Here g(n) is the function calculated for the run-time of an algorithm. And the O(g(n)) depicts the set of functions whose growth is higher than the computed function of some constant c. If the algorithm which is considered for the computation is the worst-case related scenario then the function g(n) gives the worst-case runtime function and the O(g(n)) is the worst-case runtime asymptotic notation. Basically, O(g(n)) is the set of functions and each of the functions in the set has a higher sloper than the g(n) by some constant 'c' commonly called as upper bound functions of f(n).&lt;/p&gt;

&lt;p&gt;So the Big-oh notation gives you the upper bound functions of the input function irrespective of the run-time it is calculated. If the input function of the Big-oh is the best time/ minimum run-time of an algorithm then it gives the upper bound function of that input function. If the function is the average run-time function then the Big-oh notation gives the function which has greater growth than the given input functions with the change in the size of the input.&lt;br&gt;
 &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u99zM_wf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4n5120yztsqkcpqgkjs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u99zM_wf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4n5120yztsqkcpqgkjs.png" alt="image" width="880" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the other two notations are described below&lt;/p&gt;
&lt;h3&gt;
  
  
  Theta
&lt;/h3&gt;

&lt;p&gt;The theta notation gives the functions which are asymptotically lower or which have lower slopes than the given run-time function. As in the asymptotic upper bound notation which is described with the set, THETA notation is also described using in a similar manner.&lt;/p&gt;

&lt;p&gt;The theta notation is defined as a notation that gives the functions with tight boundary limits of given run-time function by some constants. Asymptotic tight bound is denoted with the Greek letter theta.&lt;/p&gt;

&lt;p&gt;Mathematically it is defined as below:&lt;br&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;Θ(g(n))={f(n):0≤c1∗g(n)≤f(n)≤c2∗g(n),∀n≥n0}
 \Theta(g(n)) = \lbrace f(n): 0\leq c1*g(n) \leq f(n) \leq c2*g(n), \forall n \geq n0\rbrace
&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;Θ&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;g&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;))&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;{&lt;/span&gt;&lt;span class="mord mathnormal"&gt;f&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;:&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≤&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;c&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∗&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;g&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≤&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;f&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≤&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;c&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∗&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;g&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;∀&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≥&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord"&gt;0&lt;/span&gt;&lt;span class="mclose"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;The function g(n) is defined using the run-time of the algorithm, and the set is defined using the rules in such a way that the function g(n) sandwiches the function f(n) by some constants c1 and c2.&lt;/p&gt;

&lt;h3&gt;
  
  
  Omega
&lt;/h3&gt;

&lt;p&gt;Asymptotic lower bounds give you the function with lower slopes than the calculated run-time function f(n) by some constants c.&lt;br&gt;
Mathematically the asymptotic lower bound notation is defined as below:&lt;br&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;Ω(g(n))={f(n):0≤c∗g(n)≤f(n),∀n≥n0}
 \Omega(g(n)) = \lbrace f(n): 0\leq c*g(n) \leq f(n), \forall n \geq n0\rbrace
&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;Ω&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;g&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;))&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;{&lt;/span&gt;&lt;span class="mord mathnormal"&gt;f&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;:&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≤&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;c&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∗&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;g&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≤&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;f&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;∀&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≥&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord"&gt;0&lt;/span&gt;&lt;span class="mclose"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;All the functions in the set would have slower growth slopes than the computed run-time function of an algorithm. So with the change in the input to the run-time function the growth observed in the set of functions would not be a greater than the run-time function itself.&lt;/p&gt;

&lt;p&gt;Image source: Internet.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>programming</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>ES6 Promises</title>
      <dc:creator>Chaitanya</dc:creator>
      <pubDate>Wed, 15 Jan 2020 18:11:59 +0000</pubDate>
      <link>https://dev.to/bmchaitu/es6-promises-47n</link>
      <guid>https://dev.to/bmchaitu/es6-promises-47n</guid>
      <description>&lt;p&gt;Some of the features to learn in ES6 are Promises, async-await, destructuring and more.&lt;/p&gt;

&lt;p&gt;Here In this blog, we can explore the ES6 Promises and more details about them.&lt;/p&gt;

&lt;p&gt;Before to get into the Promises, we need to examine the difference between asynchronous and synchronous.&lt;/p&gt;

&lt;p&gt;Generally, when we compile the code it compiles with JIT Compiler and Intrepretes the code line after the line and continues till the end of the file.&lt;br&gt;
The execution of the code happens with-in Interpreter each line.&lt;br&gt;
Such execution is called synchronous.&lt;br&gt;
Synchronous:&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="nf"&gt;fun&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World1&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World2&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World3&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="nf"&gt;fun&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Line2 doesn't execute till the completion of the line1, and same goes with the line3. The execution start time of a new line will be after the completion of the old line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Point to remember: JavaScript is used in the Web apps and in which communication between the Client and Server happens&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It may not seem to have any problem with such the execution, but while the communication between server and client is done with the JavaScript execution, If any of the JS code executes for a long time till then the other part of the file has to wait for the completion of the execution. if it happens to take a long time(for suppose to be 10min or more), till then the other part has to hang on. Here the problem arises. Such problems can be resolved with the asynchronous execution type.&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="nf"&gt;fun&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
             &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fun1&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello from function&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="mi"&gt;2000&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello fromoutside fun&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="nf"&gt;fun&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;&lt;em&gt;Things to notice from above code:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;function fun1 is passed as a parameter to the setTimeout function(It's not a function call but a function definition itself)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;setTimeout is an in-built function which executes the passed function parameter after n seconds, where n value is passed as the second parameter to the setTimeout.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's a basic and general one to consider setTimeout as an asynchronous as it takes executes after a few seconds. Here we are using the setTimeout function for the simulation of the asynchronous type of code.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;let us consider one example for more explanation&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;myvar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Before function Myvar:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;myvar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="nf"&gt;setTimeout&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;myvar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;myvar&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
           &lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="mi"&gt;2000&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;After function Myvar:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;myvar&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;&lt;em&gt;Output&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
You may expect the output would be to print the value of myvar value as 100 and 50 respectively.&lt;br&gt;
But when you run it in v8 console you would get the output as below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbacanejgr7zw8k43peap.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbacanejgr7zw8k43peap.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to print the Myvar value as 100 and 50 respectively after the first and second console of the variable, we need to make use of ES6 features&lt;/p&gt;

&lt;p&gt;It(Asynchronous code execution) can be achieved through &lt;/p&gt;

&lt;p&gt;a. function callbacks,&lt;br&gt;
  b. Promises,&lt;br&gt;
  c. async-await functions.&lt;/p&gt;

&lt;p&gt;Here we will look at details about the Promises.&lt;/p&gt;

&lt;p&gt;Promises are in-built objects, which are instantiated with the Promise constructor. The Promise constructor takes a function as a parameter.&lt;br&gt;
Promise objects have three states in any of the execution:&lt;br&gt;
Three of the Promise states are: &lt;br&gt;
                                 a. Pending state,&lt;br&gt;
                                 b. Resolved state,&lt;br&gt;
                                 c. Rejected state.&lt;/p&gt;

&lt;p&gt;Whenever we want to execute the asynchronous code we will wrap such block in the Promise and write it so we can achieve what we require. In order to make it we instantiate an object with Promise constructor and use the object for further computing. Promise constructor has a function parameter. so we need to pass it in the call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;br&gt;
This is how we need to instantiate the Promises. At the instantiation level, all the promises would be a pending state. Now we need to include the asynchronous code in the function parameter. Thus we will look at the implementation of it. Based upon the Implementation of the promise it would resolve  Also, that parametric function also has again two function parameters. By convention, these two functions are named as resolve and reject.&lt;/p&gt;

&lt;p&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="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
                   &lt;span class="c1"&gt;//Asynchronous code block&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In the function parameter after the asynchronous code Implementation, the promise needs to be resolved into a rejected state or fulfilled state upon the success or failure of the promise.&lt;/p&gt;

&lt;p&gt;For further computation based on the results of the Promise states, we can proceed with the then or catch functions.&lt;/p&gt;

&lt;p&gt;Example scenario: If the asynchronous code is Implemented and the promise reaches the fulfilled state. Hence the result can be taken in the then method of the promise instance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Consuming Promises&lt;/em&gt;&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="nx"&gt;myvar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Myvar before function:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;myvar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                   &lt;span class="nf"&gt;setTimeout&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;myvar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;myvar&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                                    &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myvar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
                                   &lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                                 &lt;span class="c1"&gt;//promise is fulfilled with resolve call&lt;/span&gt;
                &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Myvar after function:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;'Then' method has an extra second parameter where the error of the resolved promise can be handled. resolve and reject can pass a string, variable, array or of any other data types. Here we are passing the numerical variable whose value we need it in future circumstances.&lt;/p&gt;

&lt;p&gt;But if the asynchronous code implementation is deduced that it leads to rejected state from the Pending state. Then the resultant compilation would not go to the resolve function but to the catch promise method.&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;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mypassword&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="c1"&gt;//Async code block&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;password&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mypassword&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
              &lt;span class="k"&gt;else&lt;/span&gt;
              &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Valid Password&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;password&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reslove&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="c1"&gt;//Async code block&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;password&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mypassword&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
              &lt;span class="k"&gt;else&lt;/span&gt;
              &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Valid Password&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;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid Password:Error&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;As the promise is rejected, it is handled with the catch method.&lt;/p&gt;

&lt;p&gt;Promise Object after asynchronous implementation will return the Promise object again.which is resolved/rejected.&lt;/p&gt;

&lt;p&gt;But if you want the any implementation to be resolved at a particular instance then it can be done with the resolve method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Creating settled Promises&lt;/em&gt;&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="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&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="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&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="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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;value&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;The above code prints the numerical value 3.&lt;br&gt;
so we need to pass the function for the direct transfer of a promise to resolved state. We can make it upon the function call. Note that we didn't create promise object here with new keyword but we directly called the resolve method on the promise constructor. And as stated earlier resolve method returns the Promise but fulfilled state which can be handled in 'then' method. &lt;/p&gt;

&lt;p&gt;same can be done with the reject method if one wants to reject the promise object with the rejected state. While the rejected state can be handled with the catch method.&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;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reject&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="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&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="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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rejected value:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Chaining of Promises&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
As the fulfilment of the promise to resolved state or rejected state, we consumed them separately upon the Promise object with then and catch method calls. But they can also be chained. &lt;br&gt;
Considering the above example again here.&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;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;password&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reslove&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="c1"&gt;//Async code block&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;password&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mypassword&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
              &lt;span class="k"&gt;else&lt;/span&gt;
              &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Valid Password&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="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid Password:Error&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;Note that the promise methods are defined on the same promise object 'p'. Whereas before it was defined separately on p. Such a methodology is called chaining of promises.&lt;/p&gt;

&lt;p&gt;Interested can check for:&lt;/p&gt;

&lt;p&gt;Promise.all, and various other Promise methods.&lt;br&gt;
callback functions and call back hell problem&lt;br&gt;
async-await functions.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Web Services &amp; Architecture Styles</title>
      <dc:creator>Chaitanya</dc:creator>
      <pubDate>Wed, 08 Jan 2020 12:55:09 +0000</pubDate>
      <link>https://dev.to/bmchaitu/web-services-architecture-styles-56g1</link>
      <guid>https://dev.to/bmchaitu/web-services-architecture-styles-56g1</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;b&gt;WEB-SERVICES&lt;/b&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The service offered by the components which can be invoked or used to invoke the other components over the Inter-network.&lt;/p&gt;

&lt;h5&gt;
  
  
  Web Service Implementation methods:
&lt;/h5&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        1. Using Remote procedure(RPC) 
        2. Using Service-oriented-architecture(SOA).
        3. Using Representational State Transfer(REST).
        4. Using Application Programme Interface(API).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  More About the Service:
&lt;/h3&gt;

&lt;p&gt;In the typical Client-Service architecture model, where client requests and the server responds, the &lt;strong&gt;&lt;em&gt;same&lt;/em&gt;&lt;/strong&gt; happens here in the services. Where one component(service requestor) would request an object and client(service responder) object would respond with success/failure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Service Provider:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
From where the required services can be caught with the Invocation if it has, through the service broker/service repository/service registry. It responds if it has if it doesn't then it invokes other service provider and get the objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Service Requestor:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Service requestor requests the required services and makes the resources avail to the components through the series of communications. The communication between the Service requestor and the Service Provider would happen through the Service repository/Service registry. It is called Service consumer as it consumes the services from the Service Provider.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Service Broker:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These types of services act as an intermediary component between the Service Requestor and the Service consumer. Sometimes when the Service Provider doesn't have the resources asked by the Service consumer, then the present Service consumer would request the corresponding resources for other service providers. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Let us assume Service requestor(SR1) has requested through the service broker(SB1) to the service provider SP1, but the service provider (SP1) doesn't have the corresponding resources. So now the SP1 would request the same resources to another service provider(SP2) in the name of service requestor(SR2) to the SP2 through the same/other service broke. At the same time, here SP1 is a service broker to the SR1. Eventually, It may continue as long as the resource is available. After the resource is found at SP[n]. It would return the same result to the service requestor(SR1) which might resemble Peer-to-Peer style. &lt;/p&gt;

&lt;p&gt;And Hence the same component might act as a service requestor as well as the service provider/service broker.&lt;/p&gt;
&lt;h3&gt;
  
  
  Few of the ARCHITECTURE STYLES:
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Basic Architecture styles in order:
  1.Client-Server
  2.Peer-to-Peer
  3.Monolithic
  4.Service-Oriented
  5.Micro Services
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Starting from the First&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Client-Server
&lt;/h4&gt;

&lt;p&gt;As stated above the Server is the resources provider while the client is the one who would access them. Many clients would request the same/different resources and the server shall serve all the client requests. A client can access the files from the remote as well.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4VoKU2a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/s5xh8gj6296x39n3ca9p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4VoKU2a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/s5xh8gj6296x39n3ca9p.jpg" alt="Alt Text" width="880" height="671"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Peer-to-Peer
&lt;/h4&gt;

&lt;p&gt;All the systems(Nodes) would be collectively made network and share the files among them, whenever required. Each node can access common files and folders. The sharing is done through the medium of cable, Optical fibre.&lt;br&gt;
Every node has the same processing power and Equipotent. &lt;/p&gt;

&lt;h4&gt;
  
  
  Monolithic
&lt;/h4&gt;

&lt;p&gt;The software is made upon the single and only one module. All the features and tasks will be done through the same module. Whenever the changes required to make then, the same module need to be changed and deployed the same.While the modularity of the modularity programming style is very thin. It can be compared to the analogy of the Solo player playing the game.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;New Generation Architectures:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Service-Oriented
&lt;/h4&gt;

&lt;p&gt;Encapsulating all the application logic within a few components and share them as the services among them with the common protocols such as Simple Object Access Protocol(SOAP), and the messages can be exchanged with the XML.&lt;br&gt;
Each of the Component in the SOA may have specific functionality and SOAP is the protocol used to convey the messages between the components and  HTTP protocol is used to access the application at the higher level of communication between the applications. While the Web Service Description Language(WSDL) is used in the SOA to describe the services available to other components so other components can access them. But the Implementation particulars of the services in the components are not represented in the WSDL, but to be done in the XML. In between Universal Description Discovery and Integration(UDDI) is used to describe the description, integration of the web services. &lt;br&gt;
It acts as the index of the web services available in the Web. It can be compared to the Phone Directory where all the services and the contacts are available. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tZrQpa2Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/hw3ylvfckr0r7jrc6zr5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tZrQpa2Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/hw3ylvfckr0r7jrc6zr5.png" alt="Alt Text" width="500" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A minute Issue to be discussed in the SOA is the communication between the applications of different types which are made of different programming languages an incompatibility issue is araised. This incompatibility can be resolved using the SOAP implementation methodologies of Web services through an Internet Network. This resolves the major issue in a simple fashion and made the application-to-applications communication simpler. It acts as an Interface of the different applications. It not only solves the single-layered software problem but also a multi-layered architecture problem.&lt;/p&gt;

&lt;h4&gt;
  
  
  Micro-Services
&lt;/h4&gt;

&lt;p&gt;In short, the REST is the architectural style of the Micro-services. But It can also be Implemented even in many ways. Coming to the REST it shortened from the Representational State Transfer where it means that whatever the resource/objects present would be accessed with the URLs'&lt;br&gt;
and the result would be transferred in JSON format. The REST couldn't be complete without the HTTP methods which are based on CRUD operations.&lt;br&gt;
REST is a state transfer strategy method and stateless which means that the state would not be stored.&lt;/p&gt;

&lt;p&gt;Example: You can Implement the HTTP methods on the object and the state of the resource is always checked, and the result is returned.&lt;br&gt;
Suppose that I use the HTTP Delete method and delete an Image, I could never know that it is deleted unless the GET method is imposed on the same resource and result would be found to be not found and hence the resource is deleted. Hence it can be seen as the verification method for the deleted resources.&lt;/p&gt;

&lt;p&gt;It is also to be noted that making use of URI's/URL's doesn't mean that you are using the microservices.URI's can also be used to access the other resources on the WEB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;REST-API&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
API is the way of implementing the web service access methodologies, where the services are taken and given. API acts as the gateway to Interact with any of the applications to the outside world, who wants to communicate with them.&lt;br&gt;
Example: Facebook offers the "facebook share API" which can be used to share the specified sites on your facebook wall.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--24oAIU9g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/05lkij75aequmahdlj8g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--24oAIU9g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/05lkij75aequmahdlj8g.jpeg" alt="Alt Text" width="880" height="880"&gt;&lt;/a&gt;&lt;br&gt;
In simple API is the way of modern communication between the two applications, and the results are formatted in JSON.&lt;br&gt;
The REST API is to make the resources available on the web through the REST architecture. Each of the resources in REST would have specific culture and feature viz UI, log in. Formally to be the give-and-take culture. And the API's can also be made a call through an app over the Inter-Network.&lt;br&gt;
To make it simple, the collection of services gives an application, &lt;br&gt;
where data flows within the services to make it a complete architecture.&lt;br&gt;
At last, API is not the same as of REST.&lt;/p&gt;

&lt;p&gt;Points to Check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Differences between Service Provider and Service Requestor&lt;/li&gt;
&lt;li&gt;Differences between Monolithic and SOA&lt;/li&gt;
&lt;li&gt;Differences between SOAP and API&lt;/li&gt;
&lt;li&gt;Differences between the REST and API&lt;/li&gt;
&lt;li&gt;Differences between the Microservices and API&lt;/li&gt;
&lt;li&gt;Differences between the SOAP and SOA &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Image source: From Book "&lt;strong&gt;&lt;em&gt;Service-Oriented Architecture: A field guide to XML and Web services&lt;/em&gt;&lt;/strong&gt;".&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Esoteric Programming Language</title>
      <dc:creator>Chaitanya</dc:creator>
      <pubDate>Wed, 01 Jan 2020 15:27:53 +0000</pubDate>
      <link>https://dev.to/bmchaitu/esoteric-programming-language-37</link>
      <guid>https://dev.to/bmchaitu/esoteric-programming-language-37</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iXBfhoo1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/c4uuik2013pr6mxbtxc6.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iXBfhoo1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/c4uuik2013pr6mxbtxc6.jpeg" alt="Alt Text" width="275" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  JSF*ck
&lt;/h1&gt;

&lt;p&gt;As every CS guy would always love to learn a new programming language. This Blog emphasise the fun part of the programming languages(playing with the programming language)&lt;/p&gt;

&lt;p&gt;As of Introduction&lt;br&gt;
Programming languages are divided into many types depending upon the properties they possess:&lt;br&gt;
Few of the Programming languages categorised as&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Array type&lt;/li&gt;
&lt;li&gt;Declarative type&lt;/li&gt;
&lt;li&gt;Concurrent type&lt;/li&gt;
&lt;li&gt;Esoterical type&lt;/li&gt;
&lt;li&gt;Compiled type&lt;/li&gt;
&lt;li&gt;Interpreted type&lt;/li&gt;
&lt;li&gt;Functional type
and the list goes on...&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can find the complete list in the wiki.&lt;/p&gt;

&lt;p&gt;To keep things tidy we would not go into the question of &lt;strong&gt;what properties did segregate them&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Some languages even might belong to more than one category as it would possess the specified categorical properties.&lt;br&gt;
Example: Java -It posses the properties of Declarative and Compiled type.&lt;br&gt;
               Java belongs to both categories.&lt;/p&gt;

&lt;p&gt;Now the discussion is all about the Esoterical programming languages.&lt;br&gt;
Esoterical Programming languages however, they are not meant for any software development, but to test the limitations of the conventional programming languages(as stated by the one of the sites). Learning them doesn't make you a career, but might help to play with computer and enjoy better for those who are obsessed with computer programming.&lt;/p&gt;

&lt;p&gt;Taking dive deep into the Esoterical type programming languages discussion. programming languages list under the esoterical type states as BF(Brain Fuck), JSFuck, Piet.&lt;/p&gt;

&lt;p&gt;I would like to make it short and formal to spell JSFuck as JSF in this blog.&lt;br&gt;
Now, here the discussion is about JSF It would be a tutorial for the JSF Programming Language. Among them, Piet and BF would require the special compiler to execute, whereas the JSF can be executed in the web-browser console and node as well.&lt;br&gt;
As the name suggests JSF is a subset of JavaScript and the syntax whatever would be similar to the Java Script.&lt;/p&gt;

&lt;p&gt;Those who are familiar with the JS would find of no surprise in the JSF syntax. JSF includes only 6 characters and the whole script need to be written using only those prescribed 6 characters.&lt;/p&gt;

&lt;p&gt;6 characters listed here: [, ], +, (, ), \&lt;/p&gt;
&lt;h3&gt;
  
  
  JSF an exceptional of esoterical programming languages
&lt;/h3&gt;

&lt;p&gt;Advantage of learning Esoterical languages wouldn't help but learning JSF&lt;br&gt;
make you strong with the puzzling scripts of JavaScript, which need not to scratch the head when encountered while dealing with JS.&lt;/p&gt;

&lt;p&gt;To be said in another way, to practise the confusion part of JS getting familiar with JSF will surely help&lt;/p&gt;
&lt;h3&gt;
  
  
  Making JS Basics Familiar
&lt;/h3&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="c1"&gt;//evaluates []&lt;/span&gt;
    &lt;span class="dl"&gt;''&lt;/span&gt;      &lt;span class="c1"&gt;//evaluates ''&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="dl"&gt;''&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;     &lt;span class="c1"&gt;//evaluates true&lt;/span&gt;
   &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;    &lt;span class="c1"&gt;//evaluates false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;! operator in JS returns the Boolean &lt;strong&gt;NOT&lt;/strong&gt; of the operand.&lt;br&gt;
In JS empty string, Boolean false, null considered as a falsy.&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="o"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;       &lt;span class="c1"&gt;//returns true&lt;/span&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;       &lt;span class="c1"&gt;//returns false&lt;/span&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;Nan&lt;/span&gt;      &lt;span class="c1"&gt;//returns true&lt;/span&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;     &lt;span class="c1"&gt;//return true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a Bonus, few of the JS would go&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="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="c1"&gt;//returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here null is not a Boolean yet, still, it is a special null value so it returns false. After the occurrence of the '!' operator type coercion occurs and converted into Boolean value.&lt;/p&gt;

&lt;p&gt;'+' operator is used as concatenation operator as well as the addition operator. The behaviour depends upon the operands being acted.&lt;br&gt;
If any of the operands is String it would convert the non-string operand into the String and concatenate into a new String.&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="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="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;            &lt;span class="c1"&gt;//returns Hello2 String&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="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;Nan&lt;/span&gt;         &lt;span class="c1"&gt;//returns HelloNan&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="o"&gt;+&lt;/span&gt; &lt;span class="kc"&gt;Infinity&lt;/span&gt;  &lt;span class="c1"&gt;//return Hellonfinity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Though Nan, Infinity are special values in JS, type coercion is made upon the Nan and String type result is obtained.&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="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;         &lt;span class="c1"&gt;//return Nan&lt;/span&gt;
    &lt;span class="o"&gt;+!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;        &lt;span class="c1"&gt;//returns 0&lt;/span&gt;
    &lt;span class="o"&gt;+!!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;       &lt;span class="c1"&gt;//returns 1&lt;/span&gt;
    &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;      &lt;span class="c1"&gt;//returns '2'&lt;/span&gt;
    &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;     &lt;span class="c1"&gt;//returns string&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="o"&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="c1"&gt;//returns '23'&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Detailed JSF
&lt;/h2&gt;

&lt;p&gt;In JSF as no special characters should be used except those of 6 characters makes the JSF Interesting.&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="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;            &lt;span class="c1"&gt;//value '0'&lt;/span&gt;
   &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;           &lt;span class="c1"&gt;//value '1'&lt;/span&gt;
   &lt;span class="o"&gt;+!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;           &lt;span class="c1"&gt;//value 0&lt;/span&gt;
   &lt;span class="o"&gt;+!!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;          &lt;span class="c1"&gt;//value 1&lt;/span&gt;
   &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;     &lt;span class="c1"&gt;//value 10&lt;/span&gt;
   &lt;span class="p"&gt;[][[]]&lt;/span&gt;         &lt;span class="c1"&gt;//value undefined&lt;/span&gt;
   &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]]&lt;/span&gt;         &lt;span class="c1"&gt;//value NaN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same as in JS, JSF has Constructors but with of those 6 characters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[] + []    //String Constructor

+[]        //Number Constructor

![]        //Boolean

[]         //Array Constructor

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

&lt;/div&gt;



&lt;p&gt;Whenever you want to print the value n, the value of one (+!![]) should be added to recursively 'n' times. And hence the corresponding result would be obtained.&lt;/p&gt;

&lt;p&gt;Now Whenever you want to print the alphabets, we shall extract the corresponding characters from the String and print them&lt;/p&gt;

&lt;p&gt;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="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;][&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]][&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]]&lt;/span&gt;   &lt;span class="c1"&gt;//gives f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Usage of [ ]
&lt;/h3&gt;

&lt;p&gt;An array is an object to hold one/more number of elements and each element is given an index to access. An array may also contain other arrays inside it as an element. It is legal to use such.&lt;/p&gt;

&lt;p&gt;IN JSF [ ] is regarded as an Array&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="c1"&gt;//Array&lt;/span&gt;
   &lt;span class="p"&gt;[[]]&lt;/span&gt;     &lt;span class="c1"&gt;//An array with an element at index 0 as []&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever we want to access the elements in Array we would do them with index placed within the square brackets &lt;em&gt;[]&lt;/em&gt;&lt;br&gt;
When we want to access the element at the index at 0&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="c1"&gt;//Syntax to access the elemnts in an array&lt;/span&gt;
&lt;span class="p"&gt;[][[]]&lt;/span&gt;        &lt;span class="c1"&gt;//sytax to access the '' property of object inside first[]  &lt;/span&gt;
&lt;span class="p"&gt;[[]][&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]]&lt;/span&gt;    &lt;span class="c1"&gt;//returns an empty array []&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As stated earlier [ ] is an array, and [ ] can also be used in the array elements access. Same happens here in the first expression&lt;br&gt;
To keep things simpler [array][index] supposed that 'array' is the name of an array. But remember that we don't have alphabets to name the array hence we should keep the names as with expressions.&lt;/p&gt;

&lt;p&gt;In the above second expression, we are trying to access the property of the Object stated in the RHS side. It returns the property value if it has.&lt;br&gt;
But in the expression, it is given as [ ], which evaluates as ''(empty string). Hence we are trying to access the ''(empty string) named property to an object in the RHS side.&lt;/p&gt;

&lt;p&gt;In the above third expression, there are two parts to evaluate first let us evaluate the left side expression as goes &lt;strong&gt;[[]]&lt;/strong&gt;. It can be evaluated as an expression of an array with an inner array as its element. &lt;br&gt;
And the second expression goes as &lt;strong&gt;[ +[]]&lt;/strong&gt;] as the left part of the expression evaluated as an array, the square brackets in the right-side can be used to access, so the right part needs to be given an integer value to access the elements in an array. To get the index value we are accessing we need to evaluate the inner expression of the right-side part.&lt;/p&gt;

&lt;p&gt;so upon evaluation of the inner &lt;strong&gt;+[ ]&lt;/strong&gt; expression it gives the value of 0, and at the index 0, an empty array is present so it returns an empty array.&lt;/p&gt;

&lt;p&gt;The same method to access the characters in the strings can be used.&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="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;                     &lt;span class="c1"&gt;//returns false&lt;/span&gt;
   &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;                 &lt;span class="c1"&gt;//returns false as string&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]]&lt;/span&gt;              &lt;span class="c1"&gt;//Keeping the false string in an array&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]][&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]]&lt;/span&gt;         &lt;span class="c1"&gt;//returns false takes outside from an array&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]][&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]][&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]]&lt;/span&gt;    &lt;span class="c1"&gt;//returns the 'f'&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;And the various methods can be used to extract the characters from the predefined JS words.such as true, null, undefined, Infinity, false.&lt;/p&gt;

&lt;p&gt;Isn't that fun to get the numerical values and other characters whatever you required and whenever without actually using them.&lt;/p&gt;

&lt;p&gt;Yes,It is....&lt;/p&gt;

&lt;p&gt;JSF can be used to write functions and objects as well.&lt;br&gt;
I want to make it as a series of posts and complete them.&lt;br&gt;
In the next post, we could dwell little with the Functions, classes, Objets and more. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Programming is fun, Programming languages are funnier and, post readers are the funniest :) .&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sigh.&lt;/p&gt;

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