<?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: Ankit Soni</title>
    <description>The latest articles on DEV Community by Ankit Soni (@ankysony).</description>
    <link>https://dev.to/ankysony</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%2F412178%2F342bd0bc-1705-4676-8545-a8fdea25cfda.jpg</url>
      <title>DEV Community: Ankit Soni</title>
      <link>https://dev.to/ankysony</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ankysony"/>
    <language>en</language>
    <item>
      <title>5 Reasons why javascript is hated by developers.</title>
      <dc:creator>Ankit Soni</dc:creator>
      <pubDate>Mon, 03 Aug 2020 10:19:13 +0000</pubDate>
      <link>https://dev.to/ankysony/5-reasons-why-javascript-is-hated-by-developers-2mob</link>
      <guid>https://dev.to/ankysony/5-reasons-why-javascript-is-hated-by-developers-2mob</guid>
      <description>&lt;p&gt;Javascript is a programming language build by &lt;code&gt;Brendon Eich&lt;/code&gt; in April 1995. He was told to make a language to run in &lt;code&gt;Netscape's browser&lt;/code&gt; and that too within &lt;code&gt;10 days.&lt;/code&gt;&lt;br&gt;
The hard part was producing a rich and powerful language while being prohibited from using the &lt;code&gt;object-oriented&lt;/code&gt; syntax reserved for Java. A lot of developers hate this language. Below is a comparison of it from other languages.&lt;/p&gt;

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

&lt;p&gt;In this graph, you can easily see how fast javascript has grown in terms of job opportunities from 2019 - 2020. Now you may have a doubt why it is so popular even if there are so many people who hate this language. In this post, I have tried to give you some reasons why it is being hated.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Reason 1. Loosely typed language.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Javascript is a loosely typed language, but what does it mean? It means that you don't have to declare the type of a variable while defining it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Case 1: Variables without defining any data types.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="runkit-element"&gt;
  &lt;code&gt;
    
  &lt;/code&gt;
  &lt;code&gt;
    
let a = 2;
console.log(typeof a); // logs out number
a="coding";
console.log(typeof a); // logs out string

  &lt;/code&gt;
&lt;/div&gt;
 

&lt;ul&gt;
&lt;li&gt;Case 2: NaN is a number (quite confusing)&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="runkit-element"&gt;
  &lt;code&gt;
    
  &lt;/code&gt;
  &lt;code&gt;
    
console.log(typeof NaN) // logs out number;

  &lt;/code&gt;
&lt;/div&gt;
 

&lt;ul&gt;
&lt;li&gt;Case 3: You can mix different data types in an array.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="runkit-element"&gt;
  &lt;code&gt;
    
  &lt;/code&gt;
  &lt;code&gt;
    
array = ["banana", 2 , {name: "ankit" , lastname: "soni" } ];
// please click on the run button below to see the log.
console.log(array[0] +" "+ typeof array[0]); 
console.log(array[1] +" "+ typeof array[1]); 
console.log(array[2].name+" "+array[2].lastname+" "+ typeof array[2]); 

  &lt;/code&gt;
&lt;/div&gt;
 
&lt;h3&gt;
  
  
  &lt;strong&gt;Reason 2. Concept of "==" &amp;amp;&amp;amp; "===".&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In very simple words "==" cares about equality of two variables without caring about the data types, whereas "===" cares about the equality as well as the data type of both the variables. Let's understand it better by the following example.&lt;/p&gt;


&lt;div class="runkit-element"&gt;
  &lt;code&gt;
    
  &lt;/code&gt;
  &lt;code&gt;
    
var a = 1;
var b = "1";
console.log(a == b); // prints true
console.log(a === b); // prints false

  &lt;/code&gt;
&lt;/div&gt;
&lt;br&gt;
In third line of code, double equals does not care about the data types of the variables which are different and then prints true, whereas triple equals strictly care about the data types of the variables and hence prints false.
&lt;h3&gt;
  
  
  &lt;strong&gt;Reason 3. Functions can call themselves (IIFEs)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;IIFE stands for immediate invoked function experssion. Lets learn its logic.&lt;br&gt;
&lt;/p&gt;
&lt;div class="runkit-element"&gt;
  &lt;code&gt;
    
  &lt;/code&gt;
  &lt;code&gt;
    
(function(name) {
  console.log(name); //logs out "Welcome to the ankit's blog".
})("Welcome to the ankit's blog");

  &lt;/code&gt;
&lt;/div&gt;


&lt;p&gt;This function calls itself by adding parentheses at the end of the function definition.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Reason 4. Adding two variables of different data type&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Look at the following example and try to think about the output.&lt;br&gt;
&lt;/p&gt;
&lt;div class="runkit-element"&gt;
  &lt;code&gt;
    
  &lt;/code&gt;
  &lt;code&gt;
    
var a = "12";
var b = 3;
console.log(a + b);  // logs out 123
console.log(+a + b); // logs out 15

  &lt;/code&gt;
&lt;/div&gt;


&lt;p&gt;It logs out &lt;code&gt;"123"&lt;/code&gt; and &lt;code&gt;15&lt;/code&gt; in the console but how is it happening. Javascript says that when you add number and string then &lt;code&gt;number changes to a string&lt;/code&gt;, whereas when you put a plus sign before a string then &lt;code&gt;string changes to a number&lt;/code&gt; which is quite bizarre.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Reason 5. Javascript performs differently for different browsers.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This generally happens due to the reason that every browser has its different ECMAScript engine which it uses to compile javascript code. Most famous ones are V8 by google chrome and spiderMonkey by mozilla firefox. Javascript is different from languages like c, c++ and java. Java codes are compiled the same on all the devices which are using JVM in their machines, but that does not happen with javascript. Hence a developer has to look at how their website is performing in different browsers.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;I showed you a lot of negatives about this language but don't dare to judge this language to be crappy. It has a huge internet community, as well as a lot of frameworks and libraries, are running on it. Below is the list of some of them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Front-end: &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;Reactjs&lt;/a&gt;, &lt;a href="https://angularjs.org/" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;, &lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;Vuejs&lt;/a&gt;, &lt;a href="https://emberjs.com/" rel="noopener noreferrer"&gt;emberjs&lt;/a&gt; etc.&lt;/li&gt;
&lt;li&gt;Back-end: &lt;a href="//nodejs.org/en/"&gt;Nodejs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;mobile-development:&lt;a href="https://reactnative.dev/" rel="noopener noreferrer"&gt;React native&lt;/a&gt; and &lt;a href="https://ionicframework.com/" rel="noopener noreferrer"&gt;ionic&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;game-development: &lt;a href="https://phaser.io/" rel="noopener noreferrer"&gt;Phaser&lt;/a&gt;, &lt;a href="https://www.babylonjs.com/" rel="noopener noreferrer"&gt;babylonjs&lt;/a&gt; and &lt;a href="https://playcanvas.com/" rel="noopener noreferrer"&gt;playcavasjs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Desktop application: &lt;a href="https://www.electronjs.org/" rel="noopener noreferrer"&gt;electron&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are still reading it. Consider reading my blog on &lt;code&gt;promises&lt;/code&gt; by clicking on the following link.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/ankysony" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F412178%2F342bd0bc-1705-4676-8545-a8fdea25cfda.jpg" alt="ankysony"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/ankysony/how-did-promise-evolve-in-javascript-2fcp" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How did promise evolve in Javascript? &lt;/h2&gt;
      &lt;h3&gt;Ankit Soni ・ Jul 18 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascipt&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
Thank you!

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontenddev</category>
    </item>
    <item>
      <title>How did promise evolve in Javascript? </title>
      <dc:creator>Ankit Soni</dc:creator>
      <pubDate>Sat, 18 Jul 2020 08:39:41 +0000</pubDate>
      <link>https://dev.to/ankysony/how-did-promise-evolve-in-javascript-2fcp</link>
      <guid>https://dev.to/ankysony/how-did-promise-evolve-in-javascript-2fcp</guid>
      <description>&lt;p&gt;Promise being one of the most important concepts of javascript is massively misunderstood by many developers, hence in this post firstly I will explain promise with a short story, and then we will dive deep in the code to understand it better.&lt;/p&gt;

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

&lt;h5&gt;
  
  
  INCIDENT A
&lt;/h5&gt;

&lt;p&gt;Gilbert is making a request from Godfrey to make a promise of bringing pizza base from the market. &lt;/p&gt;

&lt;h5&gt;
  
  
  INCIDENT B
&lt;/h5&gt;

&lt;p&gt;In this step, Gilbert is talking about the &lt;code&gt;asynchronous operation&lt;/code&gt; in which he is preparing vegetables without waiting for the pizza base.&lt;/p&gt;

&lt;h5&gt;
  
  
  INCIDENT C
&lt;/h5&gt;

&lt;p&gt;Godfrey is talking about how he can &lt;code&gt;return (value)&lt;/code&gt; the promise which he is making. He is also trying to ask what if he fails in keeping up with the promise.&lt;/p&gt;

&lt;h5&gt;
  
  
  INCIDENT D &amp;amp; E
&lt;/h5&gt;

&lt;p&gt;It shows that the response made by the promise can be a &lt;code&gt;success&lt;/code&gt; or &lt;code&gt;failure&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  INCIDENT F
&lt;/h5&gt;

&lt;p&gt;This is the final step where we receive the result of the promise.&lt;/p&gt;

&lt;h4&gt;
  
  
  DEFINING PROMISES IN JAVASCRIPT.
&lt;/h4&gt;

&lt;p&gt;From this short story, we learn that promise is an object which is completed or failed by doing an asynchronous(not depending on the main operation) operation. Now we can attach callbacks to this promise object (which is a pizza base in our case) to perform functions on them.&lt;/p&gt;

&lt;h4&gt;
  
  
  HOW JAVASCRIPT WORKS.
&lt;/h4&gt;

&lt;p&gt;Javascript is a single-threaded language by this I mean that it runs line by line and top to bottom, but what happens when it encounters an asynchronous function. Asynchronous function takes place in the order they complete. Let's see it in the following example.&lt;br&gt;
Can you guess what will be logged out after we run it?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&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;apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&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;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;banana&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;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;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;cherry&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;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;console result &lt;code&gt;apple cherry banana&lt;/code&gt;&lt;br&gt;
not this  &lt;del&gt;&lt;code&gt;apple banana cherry&lt;/code&gt;&lt;/del&gt;.&lt;/p&gt;

&lt;p&gt;The reason for this to happen is that even though &lt;code&gt;line 2&lt;/code&gt; started earlier than &lt;code&gt;line 3&lt;/code&gt; but the execution of &lt;code&gt;line2&lt;/code&gt; takes 2 seconds whereas &lt;code&gt;line3&lt;/code&gt; takes 1 second, so it logged out in that manner.&lt;/p&gt;
&lt;h4&gt;
  
  
  CREATING A PROMISE.
&lt;/h4&gt;

&lt;p&gt;Promise constructor takes in one argument of &lt;code&gt;callback function&lt;/code&gt; which contains two parameters &lt;code&gt;resolve&lt;/code&gt; and &lt;code&gt;reject&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Below is the method of creating a promise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;making_promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mypromise&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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="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;Now once we have created a promise we will catch it by &lt;code&gt;.then(function)&lt;/code&gt; when it is successful and by &lt;code&gt;.catch(function)&lt;/code&gt; when it is failed.&lt;/p&gt;

&lt;p&gt;In this manner.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;making_promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;coding daily&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;then&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;promised completed successfully&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&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;it made an 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;console result:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;promised completed successfully&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now if I change that &lt;code&gt;true&lt;/code&gt; to &lt;code&gt;false&lt;/code&gt; inside the if statement then we get to reject and we catch it by &lt;code&gt;.catch(function)&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;making_promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mypromise&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;making_promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;coding daily&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;then&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;promised completed successfully&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&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;it made an 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;console result:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;it made an error&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;There are three states of response in Promise.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;resolve&lt;/code&gt;: when the promise is successful.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;reject&lt;/code&gt;: when there is an error.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pending&lt;/code&gt;: when the promise is pending.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  CREATING PROMISE FOR OUR PIZZA EXAMPLE.
&lt;/h4&gt;

&lt;p&gt;So we can make our pizza promise story in code like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;createpizza&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pizza&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&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="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="s2"&gt;`preparing to make &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;pizza&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&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="p"&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;bringbase&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;got pizza base from market&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pizza created!&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;createpizza&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Margherita Pizza&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bringbase&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;console result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;preparing to make Margherita Pizza
got pizza base from market
pizza created!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While doing web development we use a lot of asynchronous operations like getting JSON data from APIs, posting something to the website, deleting the data etc..&lt;/p&gt;

&lt;p&gt;The best thing about asynchronous operations is that they do not hinder other processes occurring on the page which kind of makes the web faster and the overall experience of a user becomes good that's why it becomes important to learn asynchronous objects like Promises.&lt;/p&gt;

&lt;p&gt;Go make your own promise.&lt;br&gt;
Thank you!&lt;/p&gt;

&lt;p&gt;I will also soon be publishing it on GeeksforGeeks.&lt;/p&gt;

</description>
      <category>javascipt</category>
    </item>
  </channel>
</rss>
