<?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: John Kapantzakis</title>
    <description>The latest articles on DEV Community by John Kapantzakis (@kapantzak).</description>
    <link>https://dev.to/kapantzak</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%2F203745%2F4a0fb7e4-0cfc-4bf0-ae7e-baa0d93e720b.jpeg</url>
      <title>DEV Community: John Kapantzakis</title>
      <link>https://dev.to/kapantzak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kapantzak"/>
    <language>en</language>
    <item>
      <title>Including files created by Node.js into .Net project 🛠</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Fri, 21 Feb 2020 12:52:25 +0000</pubDate>
      <link>https://dev.to/kapantzak/including-files-created-by-node-js-into-net-project-l1m</link>
      <guid>https://dev.to/kapantzak/including-files-created-by-node-js-into-net-project-l1m</guid>
      <description>&lt;p&gt;This is the continuation of a previous post of mine&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/kapantzak" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iL7zccyK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--mb97KkEn--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/203745/4a0fb7e4-0cfc-4bf0-ae7e-baa0d93e720b.jpeg" alt="kapantzak"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kapantzak/automating-boilerplate-code-generation-with-node-js-and-handlebars-2c09" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Automating boilerplate code generation with Node.js and Handlebars&lt;/h2&gt;
      &lt;h3&gt;John Kapantzakis ・ Feb 18 '20 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#node&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cli&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#handlebars&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;In that post we had described the process of creating a set of new files, that contain boilerplate code, using the &lt;a href="https://handlebarsjs.com/"&gt;Handlebars&lt;/a&gt; library. Those files are created within the folder structure of a .Net project and they, somehow, have to be included in the project.&lt;/p&gt;

&lt;p&gt;We can find them one by one and include them manually, but it would be better if they could automatically get included into the project.&lt;/p&gt;

&lt;h1&gt;
  
  
  The project file
&lt;/h1&gt;

&lt;p&gt;Each .Net project is built by the Microsoft build engine (MSBuild). In order for the engine to know what files to include into the build process, there is a special XML file called the project file that has a language soecific extension. For C# is &lt;code&gt;.csproj&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The project file is created automatically by Visual Studio, or it can be created manually if we want to build a project without using Visual Studio. Here is a sample project file for a .Net project written in C#.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Each time we create a new file, Visual Studio includes it to the project, by adding a new entry to the XML document like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Content&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"file1.ascx"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In our case, the new files are created by a Node.js app. They are at the right place but they are not yet part of the build process. We have to add a new entry to the project file for each one of them. We can do it manually, by right clicking on each file and selecting &lt;em&gt;Include In Project&lt;/em&gt;, or we can somehow automate this process.&lt;/p&gt;
&lt;h1&gt;
  
  
  Attempt #1 (xml-js)
&lt;/h1&gt;

&lt;p&gt;As we said at the beginning, this post describes the process of including files generated from a Node.js cli to specific .Net project. We are now going to describe the first attempt of creating an automated process of including those files to the desired project file.&lt;/p&gt;

&lt;p&gt;The first idea that came to my mind was to read the &lt;code&gt;.csproj&lt;/code&gt; file in javascript, add the desired entries and recreate it. So, I found &lt;a href="https://www.npmjs.com/package/xml-js"&gt;xml-js&lt;/a&gt;, a powerfull tool that lets you convert xml to js/JSON and vice versa.&lt;/p&gt;

&lt;p&gt;The flow was something like this:&lt;/p&gt;

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

&lt;p&gt;After the new files are created, we read the &lt;code&gt;.csproj&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;convert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;xml-js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;xml&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;js&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;xml2js&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;xml&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then, we manipulate the &lt;code&gt;js&lt;/code&gt; object accordingly and we recreate a new xml structure:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;xml&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js2xml&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;compact&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="na"&gt;ignoreComment&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="na"&gt;spaces&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Finally, we replace the contents of the &lt;code&gt;.csproj&lt;/code&gt; file with the new xml structure:&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;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;filePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;xml&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After the creation of the new &lt;code&gt;.cproj&lt;/code&gt; file, I could not build the project at all (oops!)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/Dx8lG9BlDnPTa/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/Dx8lG9BlDnPTa/giphy.gif" alt="oops" width="449" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It looks that the project file is broken, and, eventually it seems logical since we are trying to manipulate a specific type of XML file in a way that is not recommended. I have never used xml-js before and I might could have achieved a better result if I tried different conifgurations.&lt;/p&gt;
&lt;h1&gt;
  
  
  Attempt #2 (&lt;code&gt;Project class&lt;/code&gt;)
&lt;/h1&gt;

&lt;p&gt;After the previous failed attempt, I searched about how to programmatically include files in .net projects and found an answer to this question on stackoverflow:&lt;/p&gt;


&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;h1&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Gn-iPj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
            &lt;a href="https://stackoverflow.com/questions/18544354/how-to-programmatically-include-a-file-in-my-project" rel="noopener noreferrer"&gt;
              How to programmatically include a file in my project?
            &lt;/a&gt;
        &lt;/h1&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Aug 31 '13&lt;/span&gt;
            &lt;span&gt;Comments: 17&lt;/span&gt;
            &lt;span&gt;Answers: 6&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/18544354/how-to-programmatically-include-a-file-in-my-project" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y9mJpuJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          48
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wif5Zq3z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;h2&gt;Background&lt;/h2&gt;
&lt;p&gt;I'm making a helper application that reformats some code files and creates new code files, which are to be added to my other project, so I could use the new code right away, but I'm having serious trouble adding that new code file into my project automatically. By the…&lt;/p&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    
      &lt;a href="https://stackoverflow.com/questions/18544354/how-to-programmatically-include-a-file-in-my-project" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
    
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;People suggested to use the class &lt;code&gt;Microsoft.Build.Evaluation.Project&lt;/code&gt; from the .Net framework and its &lt;code&gt;AddItem&lt;/code&gt; method that does exactly what we are looking for.&lt;/p&gt;

&lt;p&gt;The problem is that &lt;strong&gt;we have to use C#&lt;/strong&gt; (or VB or whatever .Net compatible language you are working with) in order to use the &lt;code&gt;Project&lt;/code&gt; class. So, we have to write a console application that uses the &lt;code&gt;Project&lt;/code&gt; class and its methods in order to add new entries to the project file.&lt;/p&gt;

&lt;p&gt;As soon as we write the console appication, we must find a way to &lt;strong&gt;execute it from Node.js&lt;/strong&gt;, since our new files are created from a Node.js cli.&lt;/p&gt;

&lt;h2&gt;
  
  
  Console application
&lt;/h2&gt;

&lt;p&gt;Lets now build a simple (C#) console application that will load the project file, add the new items and save the changes. We are not going to cover the whole process in detail, instead we are going to highlight the major points.&lt;/p&gt;

&lt;p&gt;If you want to view the whole code you can check the following repo:&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/kapantzak"&gt;
        kapantzak
      &lt;/a&gt; / &lt;a href="https://github.com/kapantzak/csproj-include"&gt;
        csproj-include
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Programmatically include items to csproj file
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
csproj-include&lt;/h1&gt;
&lt;p&gt;Programmatically include items to csproj file&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/kapantzak/csproj-include"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;Inside our &lt;code&gt;Main&lt;/code&gt; method, we check if the desired project is already loaded and if not, we load it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ProjectCollection&lt;/span&gt;
          &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GlobalProjectCollection&lt;/span&gt;
          &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LoadedProjects&lt;/span&gt;
          &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FirstOrDefault&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FullPath&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;projectFullPath&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="n"&gt;p&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Project&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;projectFullPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As soon as we have a loaded project file, we can iterate over a collection of items that represents the new entries and add them one by one to the loaded file:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ForEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;                                
    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddItemFast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;itemType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;unevaluatedInclude&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We assume that &lt;code&gt;items&lt;/code&gt; is a collection of objects of type &lt;code&gt;Item&lt;/code&gt; which is defined bellow:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Item&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;itemType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;unevaluatedInclude&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&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;h3&gt;
  
  
  Inputs
&lt;/h3&gt;

&lt;p&gt;The program needs some input in order to work properly, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The project file to load&lt;/li&gt;
&lt;li&gt;The entries collection to be inserted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We expect the first argument to be the project file and the second argument to be a JSON string that is going to be deserialised into a list of &lt;code&gt;Item&lt;/code&gt; objects.&lt;/p&gt;
&lt;h3&gt;
  
  
  Execution
&lt;/h3&gt;

&lt;p&gt;We can now call the executable like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; app.exe file.csproj &lt;span class="o"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"itemType"&lt;/span&gt;: &lt;span class="s2"&gt;"Content"&lt;/span&gt;, &lt;span class="s2"&gt;"unevaluatedInclude"&lt;/span&gt;: &lt;span class="s2"&gt;"myFile.ts"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;, &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"metadata"&lt;/span&gt;: null&lt;span class="o"&gt;}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;But when I tested, I got the following error.&lt;/p&gt;

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

&lt;p&gt;It seems that there is a missing file or directory! After a lot of searching, I found another stackoverflow question:&lt;/p&gt;


&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;h1&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Gn-iPj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
            &lt;a href="https://stackoverflow.com/questions/48771116/cant-use-microsoft-build-evaluation-in-vs2017" rel="noopener noreferrer"&gt;
              Can't use Microsoft.Build.Evaluation in VS2017
            &lt;/a&gt;
        &lt;/h1&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Feb 13 '18&lt;/span&gt;
            &lt;span&gt;Comments: 3&lt;/span&gt;
            &lt;span&gt;Answers: 3&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/48771116/cant-use-microsoft-build-evaluation-in-vs2017" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y9mJpuJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          1
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wif5Zq3z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;I built a Web Forms website using VS2015 where I user &lt;code&gt;Microsoft.Build.Evaluation&lt;/code&gt;
so that I can grammatically go through the files in my project
When using VS2017 I get this error:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Microsoft.Build.Exceptions.InvalidProjectFileException: 'The imported
  project "C:\Program Files
  (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets"
  was not found. Confirm that the path in the  declaration is
  correct…&lt;/p&gt;
&lt;/blockquote&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    
      &lt;a href="https://stackoverflow.com/questions/48771116/cant-use-microsoft-build-evaluation-in-vs2017" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
    
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;I finally found out that &lt;code&gt;$(MSBuildExtensionsPath32)&lt;/code&gt; and &lt;code&gt;$(VisualStudioVersion)&lt;/code&gt; variables of the project file was not correctly set, and that I could apply the desired settings, using an overload of the &lt;code&gt;Project&lt;/code&gt; class constructor that accepts this kind of settings.&lt;/p&gt;

&lt;p&gt;So I added the following lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;glob&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;span class="n"&gt;glob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"VisualStudioVersion"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"16.0"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;glob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"MSBuildExtensionsPath32"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;@"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Project&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;projectFullPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;glob&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And it worked just fine!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/D6WuLOKOpR2fK/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/D6WuLOKOpR2fK/giphy.gif" alt="hooray" width="320" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Execute from Node.js
&lt;/h2&gt;

&lt;p&gt;Our final step is to call the console application's executable from inside our Node.js cli. We can achieve that using the &lt;code&gt;execFile()&lt;/code&gt; method of the &lt;code&gt;child_process&lt;/code&gt; module like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;exec&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;child_process&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;execFile&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;child&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;projectFile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Workflow
&lt;/h2&gt;

&lt;p&gt;Now lets overview the workflow after our second attempt&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--61SdWjOr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zj99vv31hdtpcj23esrq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--61SdWjOr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zj99vv31hdtpcj23esrq.png" alt="Alt Text" width="327" height="501"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we described earlier, the new files are created by a Node.js cli. As soon as the files have been created, we use &lt;code&gt;execFile&lt;/code&gt; to call the console app we have created in order to add the new items to the desired project file.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;During the development process of this Node.js app and the console application, I came accross various problems that I had never faced before. I had to search a lot for the details so, I thought I could write a post about my experience in order to help other people who may face the same or similar problems. I hope you enjoyed reading! 😄&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/web-deployment-in-the-enterprise/understanding-the-project-file"&gt;Understanding the project file&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback"&gt;https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/18544354/how-to-programmatically-include-a-file-in-my-project"&gt;https://stackoverflow.com/questions/18544354/how-to-programmatically-include-a-file-in-my-project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/47077150/msbuild-15-webapplication-targets-is-missing"&gt;https://stackoverflow.com/questions/47077150/msbuild-15-webapplication-targets-is-missing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/48771116/cant-use-microsoft-build-evaluation-in-vs2017"&gt;https://stackoverflow.com/questions/48771116/cant-use-microsoft-build-evaluation-in-vs2017&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://xamarin.github.io/bugzilla-archives/18/18892/bug.html"&gt;https://xamarin.github.io/bugzilla-archives/18/18892/bug.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>dotnet</category>
      <category>csharp</category>
      <category>msbuild</category>
    </item>
    <item>
      <title>Automating boilerplate code generation with Node.js and Handlebars</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Tue, 18 Feb 2020 15:36:59 +0000</pubDate>
      <link>https://dev.to/kapantzak/automating-boilerplate-code-generation-with-node-js-and-handlebars-2c09</link>
      <guid>https://dev.to/kapantzak/automating-boilerplate-code-generation-with-node-js-and-handlebars-2c09</guid>
      <description>&lt;p&gt;In my current job, each time we need to create a new &lt;em&gt;form&lt;/em&gt; for our web app, we have to create a set of files that contain a serious amount of boileplate code, and this is time consuming.&lt;/p&gt;

&lt;p&gt;So, I have tried to build a tool that would automatically produce the initial code, and I came up with &lt;a href="https://www.npmjs.com/package/ess-dev" rel="noopener noreferrer"&gt;ess-dev&lt;/a&gt;, a &lt;strong&gt;project specific&lt;/strong&gt; node cli that uses &lt;a href="https://handlebarsjs.com/" rel="noopener noreferrer"&gt;Handlebars&lt;/a&gt; internally.&lt;/p&gt;

&lt;h1&gt;
  
  
  Usage
&lt;/h1&gt;

&lt;p&gt;Lets create a dummy project so that we can test our tool.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Node.js installed on your machine&lt;/li&gt;
&lt;li&gt;Internet connection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create a new folder somewhere in your computer and navigate to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; mkdir testProject
&amp;gt; cd testProject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Initialize a new npm package&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Install ess-dev package from npm&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; npm i --save-dev ess-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We now have to create the following folder structure because our tool searches for specific paths in order to write the new files.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
+-- package.json
+-- Async
+-- classes
|   +--HttpRequestsDataModels
+-- src
|   +--asyncHelpers
|   +--pageScripts
|   +--reduxStates
+-- eStudio.csproj
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Note that we have to create a file called &lt;code&gt;eStudio.csproj&lt;/code&gt; with contents that you can find in the following gist&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Add a script to the &lt;code&gt;package.json&lt;/code&gt; so we can use our cli from npm&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;scripts&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ess-dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ess-dev init&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are now ready to use our tool!&lt;/p&gt;

&lt;p&gt;Assuming that you are in the root directory of the project (On the &lt;code&gt;package.json&lt;/code&gt; level):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; npm run ess-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When asked to provide a user control name, type any name you want but prefix it with &lt;code&gt;uc&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Just hit enter to the next questions and the new files should be created to the specified paths as shown to next images.&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%2Flajliyof7n5jdpjrkktp.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%2Flajliyof7n5jdpjrkktp.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2F5ojbzr96rdk2egniknny.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%2F5ojbzr96rdk2egniknny.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the tool terminates successfully, it should provide a structure of the newly generated files as shown in the last image.&lt;/p&gt;

&lt;h1&gt;
  
  
  How does it work?
&lt;/h1&gt;

&lt;p&gt;Here's an overview of the tool's workflow.&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%2Fmgnjpqfur33du78owchn.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%2Fmgnjpqfur33du78owchn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;User provides some input, the tool searches for predefined template files, creates the new files from them using the handlebars library and writes them to specific paths.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools used
&lt;/h2&gt;

&lt;p&gt;The following tools have been used in order to develop this tool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://handlebarsjs.com/" rel="noopener noreferrer"&gt;handlebars&lt;/a&gt; to read templates and create new files&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/chalk" rel="noopener noreferrer"&gt;chalk&lt;/a&gt; to display console test in color&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/figlet" rel="noopener noreferrer"&gt;figlet&lt;/a&gt; to display beautiful fonts on the console&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/inquirer" rel="noopener noreferrer"&gt;inquirer&lt;/a&gt; to create the cli&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/log-symbols" rel="noopener noreferrer"&gt;log-symbols&lt;/a&gt; to display simple icons&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/treeify" rel="noopener noreferrer"&gt;treeify&lt;/a&gt; to produce tree structures for the console&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/xml-js" rel="noopener noreferrer"&gt;xml-js&lt;/a&gt; to read, edit and create xml documents&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/yargs" rel="noopener noreferrer"&gt;yargs&lt;/a&gt; for arguments parsing&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/jest" rel="noopener noreferrer"&gt;jest&lt;/a&gt; for testing&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Automating repetitive and time consuming tasks can save you a lot of time and effort while at the same time prevents from human errors.&lt;/p&gt;

&lt;p&gt;This tool has been developed for specific project and is not aimed to be used out of the box for other projects. On the other hand, for anyone interested, feel free to get the code and change it according to your needs.&lt;/p&gt;

&lt;h1&gt;
  
  
  Links
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/ess-dev" rel="noopener noreferrer"&gt;ess-dev: npm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/kapantzak/ess-dev" rel="noopener noreferrer"&gt;ess-dev: Github&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>cli</category>
      <category>javascript</category>
      <category>handlebars</category>
    </item>
    <item>
      <title>CSS cascade: Importance</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Wed, 04 Dec 2019 12:04:39 +0000</pubDate>
      <link>https://dev.to/kapantzak/css-cascade-importance-2g3k</link>
      <guid>https://dev.to/kapantzak/css-cascade-importance-2g3k</guid>
      <description>&lt;p&gt;While preparing for Microsoft's &lt;a href="https://www.microsoft.com/en-us/learning/exam-70-480.aspx" rel="noopener noreferrer"&gt;70-480 exam&lt;/a&gt; I came across a question in which I had to sort different stylesheets according to their origin and importance, and I got a bit confused.&lt;/p&gt;

&lt;p&gt;Even though I'm using CSS for more than 10 years, I've never dig into the specs to find out more about the terminology. When I finally spotted the right place in the &lt;a href="https://www.w3.org/TR/css-cascade-3/#cascading" rel="noopener noreferrer"&gt;specification&lt;/a&gt; it got more clear to me and I've decided to provide a simple illustration.&lt;/p&gt;

&lt;h1&gt;
  
  
  Cascaded value
&lt;/h1&gt;

&lt;p&gt;The cascading algorithm takes an unodrered list of declared values and outputs a single value that is called the &lt;strong&gt;cascaded value&lt;/strong&gt;. The algoritm takes into account 3 factors:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Importance&lt;/strong&gt;: The importance of each declaration&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Specificity&lt;/strong&gt;: The specificity of the css selectors&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order&lt;/strong&gt;: The order of the css declarations in the source code&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The following illustration presents the way that the cascade algorithm determines the final declaration (cascaded value).&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%2Fk8863vpbqiqgeiv6cvvw.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%2Fk8863vpbqiqgeiv6cvvw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets verify the above diagram with a real example:&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%2Fnh6bt3xh5xjwqo54cms9.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%2Fnh6bt3xh5xjwqo54cms9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are not going to cover all 3 steps of the cascading process, instead, we are going to explain only the first step, the &lt;strong&gt;importance&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Just to clarify some basic terms, consider the following rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;#ececec&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;background-color&lt;/code&gt; string defines a CSS property and is called a &lt;strong&gt;property declaration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;#ececec&lt;/code&gt; is the value given to the aforementioned property and is called the &lt;strong&gt;declared value&lt;/strong&gt;.&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%2Fq7dzyfbwqccpms1nde0x.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%2Fq7dzyfbwqccpms1nde0x.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, imagine that we have multiple CSS rules applied to the same element, declaring different values to the same property.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;These rules may be at the same file, or may derive from different origins. The cascading algorithm has to choose one of those values to be the cascaded value.&lt;/p&gt;

&lt;h1&gt;
  
  
  Origin
&lt;/h1&gt;

&lt;p&gt;There are 3 main origins defined in CSS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Author origin&lt;/strong&gt;: The rules written by a web developer (the author of the page)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User origin&lt;/strong&gt;: The final user of the browser may be able to alter the user agent's default styles&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User agent origin&lt;/strong&gt;: The default styles applied by the browser&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;plus 2 additions from CSS extensions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Animation origin&lt;/strong&gt;: Rules created by CSS animations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transition origin&lt;/strong&gt;: Rules created by CSS transitions&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Importance
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Normal&lt;/strong&gt;: The default state of declarations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Important&lt;/strong&gt;: Any declaration with the &lt;code&gt;!important&lt;/code&gt; annotation&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Order by origin and importance
&lt;/h1&gt;

&lt;p&gt;Specification defines the following precedence for the above combinations in descending order (Top wins):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Transition declarations&lt;/li&gt;
&lt;li&gt;Important user agent declarations&lt;/li&gt;
&lt;li&gt;Important user declarations&lt;/li&gt;
&lt;li&gt;Important author declarations&lt;/li&gt;
&lt;li&gt;Animation declarations&lt;/li&gt;
&lt;li&gt;Normal author declarations&lt;/li&gt;
&lt;li&gt;Normal user declarations&lt;/li&gt;
&lt;li&gt;Normal user agent declarations&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lets demonstarte the above hierarchy with some examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  Normal user agent declarations
&lt;/h3&gt;

&lt;p&gt;We start with a simple HTML page with only one &lt;code&gt;p&lt;/code&gt; element and no css declared, like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In this case, what style is going to be applied to the document? The answer is the default user agent style. Opening the developers tools in Chrome (&lt;em&gt;Version 78.0.3904.108&lt;/em&gt;) we see the following:&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%2Fp8nzwh7uupb1y6lh5k4k.jpg" 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%2Fp8nzwh7uupb1y6lh5k4k.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As soon as we do not provide any kind of style, the browser applies the default user agent style.&lt;/p&gt;

&lt;h3&gt;
  
  
  Normal author over normal user agent declarations
&lt;/h3&gt;

&lt;p&gt;Now, lets add a css file and add a rule for the &lt;code&gt;p&lt;/code&gt; tag:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;After we reference the new css file inside out HTML, we reload the page and we inspect the &lt;code&gt;p&lt;/code&gt; element:&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%2Fjyn8lk7v8qxinzjuei03.jpg" 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%2Fjyn8lk7v8qxinzjuei03.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we can verify the precedence of normal author declaration over user agent declaration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Animations over normal author declarations
&lt;/h3&gt;

&lt;p&gt;What happens if we add an animation declaration?&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;According to the specification,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The last declaration in document order wins &lt;a href="https://www.w3.org/TR/css-cascade-3/#cascade-order" rel="noopener noreferrer"&gt;(see here)&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, we have intentionally placed the &lt;code&gt;color: green&lt;/code&gt; declaration after the animation declaration, in order to verify that animations takes precedence over normal author declarations, regardless of their location inside the source code.&lt;/p&gt;

&lt;p&gt;The following screenshot illustrates the fact that animation declarations take precedence over normal author declarations, even if the latter are placed after the former, inside the source code.&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%2Fajql21pp1r1dplwyha28.jpg" 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%2Fajql21pp1r1dplwyha28.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Important author over normal author declarations
&lt;/h3&gt;

&lt;p&gt;According to the specification&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The importance of a declaration is based on whether or not it is declared &lt;code&gt;!important&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The following screenshot illustrates the precedence of an important author declaration (&lt;code&gt;color: blue !important&lt;/code&gt;) over a normal one.&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%2F4nsk7qn752wu7z51c9uf.jpg" 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%2F4nsk7qn752wu7z51c9uf.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Final thoughts
&lt;/h1&gt;

&lt;p&gt;We have investigated the internals of the cascade algorithm and provided some simple examples trying to verify the expected behaviour.&lt;/p&gt;

&lt;p&gt;We have, explicitly, verified the following facts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Precedence of normal author over normal user agent declarations&lt;/li&gt;
&lt;li&gt;Precedence of animations over normal author declarations&lt;/li&gt;
&lt;li&gt;Precedence of important author over normal author declarations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;During the process of writing this post, I have tried to verify the predence of &lt;strong&gt;normal author declaration over normal user declaration&lt;/strong&gt;, but I have failed to reproduce the expected behaviour, as shown in the following screenshot.&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%2Fccuewu7v9ji662p5fvwl.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%2Fccuewu7v9ji662p5fvwl.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, I tried to add some user style declarations (&lt;code&gt;color: blue;&lt;/code&gt;) using the developer tools, but it seems that this rule takes precedence over the normal author declaration (&lt;code&gt;color: green;&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;For anyone interested, here is a &lt;a href="https://stackoverflow.com/questions/59153785/css-cascading-precedence-of-origin-and-importance" rel="noopener noreferrer"&gt;question&lt;/a&gt; I've posted on Stack Overflow regarding this issue.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Chrome version 78.0.3904.108 was used for the above examples&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/css-cascade-3/#value-stages" rel="noopener noreferrer"&gt;W3C - Value Processing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/css-cascade-3/#cascading" rel="noopener noreferrer"&gt;W3C - Cascading&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/css-transitions-1/" rel="noopener noreferrer"&gt;W3C - Transitions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/css-animations-1/" rel="noopener noreferrer"&gt;W3C - Animations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance" rel="noopener noreferrer"&gt;MDN - Cascade and inheritance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/18252356/what-is-the-difference-between-default-user-and-author-style-sheets" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/18252356/what-is-the-difference-between-default-user-and-author-style-sheets&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>css</category>
      <category>priority</category>
      <category>style</category>
      <category>cascade</category>
    </item>
    <item>
      <title>JS illustrated: Promises</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Tue, 08 Oct 2019 14:02:43 +0000</pubDate>
      <link>https://dev.to/kapantzak/js-illustrated-promises-3ign</link>
      <guid>https://dev.to/kapantzak/js-illustrated-promises-3ign</guid>
      <description>&lt;p&gt;This is the second &lt;strong&gt;JS illustrated&lt;/strong&gt; article I've wrote. The first one was about the event loop&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/kapantzak" 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%2F203745%2F4a0fb7e4-0cfc-4bf0-ae7e-baa0d93e720b.jpeg" alt="kapantzak"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kapantzak/js-illustrated-the-event-loop-4mco" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JS illustrated: The event loop 🔁&lt;/h2&gt;
      &lt;h3&gt;John Kapantzakis ・ Aug 15 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;ES6 (&lt;a href="https://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects" rel="noopener noreferrer"&gt;ECMAScript 2015&lt;/a&gt;) has introduced a new feature called &lt;em&gt;Promise&lt;/em&gt;. There are numerous excelent articles and books that explain the way that Promises work. In this article, we are going to try to provide a simple and understandable description of how Promises work, without digging into much detail.&lt;/p&gt;

&lt;p&gt;Before we start explaining what a promise is and how it works, we need to take a look at the reason of its existence, in order to understand it correctly. In other words, we have to identify the problem that this new feature is trying to solve.&lt;/p&gt;

&lt;h1&gt;
  
  
  Callbacks
&lt;/h1&gt;

&lt;p&gt;Promises are inextricably linked to &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous" rel="noopener noreferrer"&gt;asynchrony&lt;/a&gt;. Before Promises, developers were able to write asynchronous code using callbacks. A callback is a function that is provided as parameter to another function, in order to be called, at some point in the future, by the latter function.&lt;/p&gt;

&lt;p&gt;Lets take a look at the following code&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We are calling &lt;code&gt;ajaxCall&lt;/code&gt; function passing a url path as first argument and a callback function as the second argument. The &lt;code&gt;ajaxCall&lt;/code&gt; function is supposed to execute a request to the provided url and call the callback function when the response is ready. In the meanwhile, the program continues its execution (the &lt;code&gt;ajaxCall&lt;/code&gt; does not block the execution). That's an asynchronous piece of code.&lt;/p&gt;

&lt;p&gt;This works great! But there are some problems that might arise, like the following (&lt;a href="https://www.amazon.com/You-Dont-Know-JS-Performance/dp/1491904224" rel="noopener noreferrer"&gt;Kyle Simpson, 2015, You don't know JS: Async &amp;amp; Performance, 42&lt;/a&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The callback function never gets called&lt;/li&gt;
&lt;li&gt;The callback function gets called too early&lt;/li&gt;
&lt;li&gt;The callback function gets called too late&lt;/li&gt;
&lt;li&gt;The callback function gets called more than once&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These problems might be more difficult to be solved if the calling function (&lt;code&gt;ajaxCall&lt;/code&gt;) is an external tool that we are not able to fix or even debug.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It seems that a serious problem with callbacks is that they give the control of our program execution to the calling function, a state known as &lt;a href="https://en.wikipedia.org/wiki/Inversion_of_control" rel="noopener noreferrer"&gt;&lt;em&gt;inversion of control&lt;/em&gt;&lt;/a&gt; (&lt;strong&gt;IoC&lt;/strong&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The following illustration shows the program flow of a callback based asynchronous task. We assume that we call a third party async function passing a callback as one of its parameters. The red areas indicate that we do not have the control of our program flow in these areas. We do not have access to the third party utility, so the right part of the illustration is red. The red part in the left side of the illustration indicates that we do not have the control of our program until the third party utility calls the callback function we provided.&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%2Frqchyt5pvcnd1cl057el.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%2Frqchyt5pvcnd1cl057el.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But wait, there's something else, except from the IoC issue, that makes difficult to write asynchronous code with callbacks. It is known as the &lt;a href="http://callbackhell.com/" rel="noopener noreferrer"&gt;callback hell&lt;/a&gt; and describes the state of multiple nested callbacks, as shown in the following snippet.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As we can see, multiple nested callbacks makes our code &lt;strong&gt;unreadable&lt;/strong&gt; and difficult to debug.&lt;/p&gt;

&lt;p&gt;So, in order to recap, the main problems that arise from the use of callbacks are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Losing the control of our program execution (Inversion of Control)&lt;/li&gt;
&lt;li&gt;Unreadable code, especially when using multiple nested callbacks&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Promises
&lt;/h1&gt;

&lt;p&gt;Now lets see what Promises are and how they can help us to overcome the problems of callbacks.&lt;/p&gt;

&lt;p&gt;According to MDN&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Promise object represents the &lt;strong&gt;eventual&lt;/strong&gt; completion (or failure) of an asynchronous operation, and its resulting value.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Promise is a &lt;strong&gt;proxy&lt;/strong&gt; for a value not necessarily known when the promise is created&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What's new here is that asynchronous methods can be called and return something immediately, in contrast to callbacks where you had to pass a callback function and hope that the async function will call it some time in the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But what's that it gets returned?&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;em&gt;It is a promise that some time in the future you will get an actual value.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;For now, you can continue your execution using this promise as a &lt;strong&gt;placeholder of the future value&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Lets take a look at the constructor&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We create a Promise with the &lt;code&gt;new Promise()&lt;/code&gt; statement, passing a function, called the &lt;strong&gt;executor&lt;/strong&gt;. The executor gets called immediately at the time we create the promise, passing two functions as the first two arguments, the &lt;strong&gt;resolve&lt;/strong&gt; and the &lt;strong&gt;reject&lt;/strong&gt; functions respectively. The executor usually starts the asynchronous operation (the &lt;code&gt;setTimeout()&lt;/code&gt; function in our example).&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;resolve&lt;/em&gt; function is called when the asynchronous task has been successfully completed its work. We then say that the promise has been &lt;strong&gt;resolved&lt;/strong&gt;. Optionally yet very often, we provide the result of the asynchronous task to the resolve function as the first argument.&lt;/p&gt;

&lt;p&gt;In the same way, in case where the asynchronous task has failed to execute its assigned task, the &lt;em&gt;reject&lt;/em&gt; function gets called passing the error message as the first argument and now we say that the promise has been &lt;strong&gt;rejected&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The next illustration presents the way that promises work. We see that, even if we use a third party utility, we still have the control of our program flow because we, immediately, get back a promise, a placeholder that we can use in place of the actual future value.&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%2F4p38iy08e1zxli9umt1c.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%2F4p38iy08e1zxli9umt1c.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;According to Promises/A+ specification&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A promise must be in one of three states: pending, fulfilled, or rejected&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When a promise is in &lt;em&gt;pending&lt;/em&gt; state, it can either transition to the &lt;em&gt;fullfilled&lt;/em&gt; (resolved) or the &lt;em&gt;rejected&lt;/em&gt; state.&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%2Fs7eyl759whe2d15iea81.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%2Fs7eyl759whe2d15iea81.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What's very important here is that, if a promise gets one of the fulfiled or rejected state, &lt;strong&gt;it cannot change its state and value&lt;/strong&gt;. This is called &lt;strong&gt;immutable identity&lt;/strong&gt; and protects us from unwanted changes in the state that would lead to undescoverable bugs in our code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting control back
&lt;/h3&gt;

&lt;p&gt;As we saw earlier, when we use callbacks we rely on another piece of code, often writen by a third party, in order to trigger our callback function and continue the execution of the program.&lt;/p&gt;

&lt;p&gt;With promises we do not rely on anyone in order to continue our program execution. We have a promise in our hands that we will get an actual value at some point in the future. For now, we can use this promise as a placeholder of our actual value and continue our program execution just as we would do in synchronous programming.&lt;/p&gt;

&lt;h3&gt;
  
  
  Readable async code
&lt;/h3&gt;

&lt;p&gt;Promises make our code more readable compared to callbacks (remember the callback hell?). Check out the following snippet:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We can chain multiple promises in a sequential manner and make our code look like synchronous code, avoiding nesting multiple callbacks one inside another.&lt;/p&gt;

&lt;h3&gt;
  
  
  Promise API
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Promise&lt;/code&gt; object exposes a set of static methods that can be called in order to execute specific tasks. We are going to briefly present each on of them with some simple illustrations whenever possible.&lt;/p&gt;

&lt;h4&gt;
  
  
  Promise.reject(reason)
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Promise.reject()&lt;/code&gt; creates an immediately rejected promise and it is a shorthand of the following code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The next snippet shows that &lt;code&gt;Promise.reject()&lt;/code&gt; returns the same rejected promise with a traditionally constructed promise (&lt;code&gt;new Promise()&lt;/code&gt;) that gets immediately rejected with the same reason.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h4&gt;
  
  
  Promise.resolve(value)
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Promise.resolve()&lt;/code&gt; creates an immediately resolved promise with the given value. It is a shorthand of the following code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Comparing a promise constructed with the &lt;code&gt;new&lt;/code&gt; keyword and then, immediately resolved with value &lt;code&gt;1&lt;/code&gt;, to a promise constructed by &lt;code&gt;Promise.resolve()&lt;/code&gt; with the same value, we see that both of them return identical results.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h5&gt;
  
  
  Thenables
&lt;/h5&gt;

&lt;p&gt;According to Promises/A+ specification&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;thenable&lt;/em&gt; is an object or function that defines a &lt;code&gt;then&lt;/code&gt; method&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lets see a &lt;em&gt;thenable&lt;/em&gt; in action in the following snippet. We declare the &lt;code&gt;thenable&lt;/code&gt; object that has a &lt;code&gt;then&lt;/code&gt; method which immediately calls the second function with the &lt;code&gt;"Rejected"&lt;/code&gt; value as argument. As we can see, we can call the &lt;code&gt;then&lt;/code&gt; method of &lt;code&gt;thenable&lt;/code&gt; object passing two functions the second of which get called with the &lt;code&gt;"Rejected"&lt;/code&gt; value as the first argument, just like a promise.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;But what if we want to use the &lt;code&gt;catch&lt;/code&gt; method as we do with promises?&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Oops! En error indicating that the &lt;code&gt;thenable&lt;/code&gt; object does not have a &lt;code&gt;catch&lt;/code&gt; method available occurs! That's normal because that's the case. We have declared a plain object with only one method, &lt;code&gt;then&lt;/code&gt;, that &lt;strong&gt;happens&lt;/strong&gt; to conform, in some degree, to the promises api behaviour. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In any case, &lt;strong&gt;it doesn't mean that an object which exposes a &lt;code&gt;then&lt;/code&gt; method, is a promise object&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But how can &lt;code&gt;Promise.resolve()&lt;/code&gt; help with this situation?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Promise.resolve()&lt;/code&gt; can accept a &lt;em&gt;thenable&lt;/em&gt; as its argument and then return a promise object. Lets treat our &lt;code&gt;thenable&lt;/code&gt; object as a promise object.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;code&gt;Promise.resolve()&lt;/code&gt; can be used as a tool of converting objects to promises.&lt;/p&gt;

&lt;h4&gt;
  
  
  Promise.all(iterable)
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Promise.all()&lt;/code&gt; waits for all promises in the provided iterable to be resolved and, then, returns an array of the values from the resolved promises &lt;strong&gt;in the order they were specified in the iterable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the following example, we declare 3 promises, &lt;code&gt;p1&lt;/code&gt;, &lt;code&gt;p2&lt;/code&gt; and &lt;code&gt;p3&lt;/code&gt; which they all get resolved after a specific amount of time. We intentionaly resolve &lt;code&gt;p2&lt;/code&gt; before &lt;code&gt;p1&lt;/code&gt; to demonstrate that the order of the resolved values that get returned, is the order that the promises were declared in the array passed to &lt;code&gt;Promise.all()&lt;/code&gt;, and not the order that these promises were resolved.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the upcoming illustrations, the green circles indicate that the specific promise has been resolved and the red circles, that the specific promise has been rejected.&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%2F5aum0ohxf7djz97sekez.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%2F5aum0ohxf7djz97sekez.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But what happens if one or more promises get rejected? The promise returned by &lt;code&gt;Promise.all()&lt;/code&gt; gets rejected with the value of the first promise that got rejected among the promises contained in the iterable.&lt;/p&gt;

&lt;p&gt;Even if more than one promises get rejected, the final result is a rejected promise with the value of the &lt;strong&gt;first promise which was rejected&lt;/strong&gt;, and not an array of rejection messages.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&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%2F26ipydz90e2qtquwvh6o.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%2F26ipydz90e2qtquwvh6o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Promise.allSettled(iterable)
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Promise.allSettled()&lt;/code&gt; behaves like &lt;code&gt;Promise.all()&lt;/code&gt; in the sence that it waits far all promises to be fullfiled. The difference is in the outcome.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see in the above snippet, the promise returned by the &lt;code&gt;Promise.allSettled()&lt;/code&gt; gets resolved with an array of objects describing the status of the promises that were passed.&lt;/p&gt;

&lt;h4&gt;
  
  
  Promise.race(iterable)
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Promise.race()&lt;/code&gt; waits for the first promise to be resolved or rejected and resolves, or rejects, respectively, the promise returned by &lt;code&gt;Promise.race()&lt;/code&gt; with the value of that promise.&lt;/p&gt;

&lt;p&gt;In the following example, &lt;code&gt;p2&lt;/code&gt; promise resolved before &lt;code&gt;p1&lt;/code&gt; got rejected.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&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%2F7xdypmymigrdmhzyooem.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%2F7xdypmymigrdmhzyooem.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we change the delays, and set &lt;code&gt;p1&lt;/code&gt; to be rejected at 100ms, before &lt;code&gt;p2&lt;/code&gt; gets resolved, the final promise will be rejected with the respecive message, as shown in the following illustration.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&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%2Fqxqjylr65q2alw939jmz.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%2Fqxqjylr65q2alw939jmz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Promise.prototype methods
&lt;/h3&gt;

&lt;p&gt;We are now going to take a look at some methods exposed by the promise's prototype object. We have already mentioned some of them previously, and now, we are going to take a look at each one of them in more detail.&lt;/p&gt;

&lt;h4&gt;
  
  
  Promise.prototype.then()
&lt;/h4&gt;

&lt;p&gt;We have already used &lt;code&gt;then()&lt;/code&gt; many times in the previous examples. &lt;code&gt;then()&lt;/code&gt; is used to handle the settled state of promises. It accepts a resolution handler function as its first parameter and a rejection handler function as its second parameter, and returns a promise.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The next two illustrations present the way that a &lt;code&gt;then()&lt;/code&gt; call operates.&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%2Fot07iq679691vqrwtdxf.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%2Fot07iq679691vqrwtdxf.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fhvo6z101qxlcthteq6fi.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%2Fhvo6z101qxlcthteq6fi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the resolution handler of a &lt;code&gt;then()&lt;/code&gt; call of a resolved promise is not a function, then no error is thrown, instead, the promise returned by &lt;code&gt;then()&lt;/code&gt; carries the resolution value of the previous state.&lt;/p&gt;

&lt;p&gt;In the following snippet, &lt;code&gt;p1&lt;/code&gt; is resolved with value &lt;code&gt;1&lt;/code&gt;. Calling &lt;code&gt;then()&lt;/code&gt; with no arguments will return a new promise with &lt;code&gt;p1&lt;/code&gt; resolved state. Calling &lt;code&gt;then()&lt;/code&gt; with an &lt;code&gt;undefined&lt;/code&gt; resolution handler and a valid rejection handler will do the same. Finally, calling &lt;code&gt;then()&lt;/code&gt; with a valid resolution handler will return the promise's value.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The same will happen in case that we pass an invalid rejection handler to a &lt;code&gt;then()&lt;/code&gt; call of a rejected promise.&lt;/p&gt;

&lt;p&gt;Lets see the following illustrations that present the flow of promises resolution or rejection using &lt;code&gt;then()&lt;/code&gt;, assuming that &lt;code&gt;p1&lt;/code&gt; is a resolved promise with value &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;p2&lt;/code&gt; is a rejected promise with reason &lt;code&gt;"Error"&lt;/code&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&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%2Fny5qz8z5csi1kniwhkfi.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%2Fny5qz8z5csi1kniwhkfi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We see that if we don't pass any arguments or if we pass non-function objects as parametes to &lt;code&gt;then()&lt;/code&gt;, the returned promise keeps the state (&lt;code&gt;resolved / rejected&lt;/code&gt;) and the value of the initial state without throwing any error.&lt;/p&gt;

&lt;p&gt;But what happens if we pass a function that does not return anything? The following illustration shows that in such case, the returned promise gets resolved or rejected with the &lt;code&gt;undefined&lt;/code&gt; value.&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%2Fgskdsc6e77mpkfp0l1my.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%2Fgskdsc6e77mpkfp0l1my.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Promise.prototype.catch()
&lt;/h4&gt;

&lt;p&gt;We call &lt;code&gt;catch()&lt;/code&gt; when we want to handle rejected cases only. &lt;code&gt;catch()&lt;/code&gt; accepts a rejection handler as a parameter and returns another promise so it can be chained. It is the same as calling &lt;code&gt;then()&lt;/code&gt;, providing an &lt;code&gt;undefined&lt;/code&gt; or &lt;code&gt;null&lt;/code&gt; resolution handler as the first parameter. Lets see the following snippet.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the next illustration we can see the way that &lt;code&gt;catch()&lt;/code&gt; operates. Notice the second flow where we throw an error inside the resolution handler of the &lt;code&gt;then()&lt;/code&gt; function and &lt;strong&gt;it never gets caught&lt;/strong&gt;. That happens because this is an asynchronous operation and this error wouldn't have been caught even if we had executed this flow inside a &lt;code&gt;try...catch&lt;/code&gt; block.&lt;/p&gt;

&lt;p&gt;On the other hand, the last illustration shows the same case, with an additional &lt;code&gt;catch()&lt;/code&gt; at the end of the flow, that, actually, catches the error.&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%2Fa1o496gxd82cfkkalllj.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%2Fa1o496gxd82cfkkalllj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Promise.prototype.finally()
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;finally()&lt;/code&gt; can be used when we do not care wheather the promise has been resolved or rejected, just if the promise has been settled. &lt;code&gt;finally()&lt;/code&gt; accepts a function as its first parameter and returns another promise.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The promise which is returned by the &lt;code&gt;finally()&lt;/code&gt; call is resolved with the resolution value of the initial promise.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Promises is a wide topic that cannot be fully covered by an article. I've tried to present some simple illustrations that will help the reader to get an idea of the way that promises work in Javascript.&lt;/p&gt;

&lt;p&gt;If you find any errors or ommisions, please do not hestitate to mention them! I've put a lot of effort to write this article and I've learned many things about promises. I hope you liked it 😁&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" rel="noopener noreferrer"&gt;MDN: Promise&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://promisesaplus.com/" rel="noopener noreferrer"&gt;Promises/A+&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/web/fundamentals/primers/promises" rel="noopener noreferrer"&gt;developers.google&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/You-Dont-Know-JS-Performance/dp/1491904224" rel="noopener noreferrer"&gt;Kyle Simpson, 2015, You don't know JS: Async &amp;amp; Performance, 29-119&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Qg1SvpIau6U"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>promises</category>
      <category>async</category>
    </item>
    <item>
      <title>The RGB split effect with css and a bit of javascript</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Mon, 16 Sep 2019 14:19:15 +0000</pubDate>
      <link>https://dev.to/kapantzak/the-rgb-split-effect-with-css-and-a-bit-of-javascript-4j4i</link>
      <guid>https://dev.to/kapantzak/the-rgb-split-effect-with-css-and-a-bit-of-javascript-4j4i</guid>
      <description>&lt;p&gt;While developing my personal website, I came accross this amazing library, &lt;a href="https://blotter.js.org/"&gt;Blotter.js&lt;/a&gt;, which exposes several methods (materials) that apply various effect on texts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blotter.js.org/#/materials/ChannelSplitMaterial"&gt;ChannelSplitMaterial&lt;/a&gt; is one of those effects that piqued my interest.&lt;/p&gt;

&lt;p&gt;The idea behind this effect is simple, just split up the red, green and blue pixels and place them in different location from the original one. And that's just what we are going to do!&lt;/p&gt;

&lt;p&gt;But first, lets see what the final result looks like&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/giannisKapa/embed/BaBJywb?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Lets start with the HTML&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;#wrapper&lt;/code&gt; element just holds the affected element, the &lt;code&gt;#text&lt;/code&gt; div. The &lt;code&gt;#text&lt;/code&gt; div holds the text that we are going to apply the RGB effect to.&lt;/p&gt;

&lt;p&gt;Now, we need to create a function that takes one argument, the HTML element to be affected. Lets call this function &lt;code&gt;channelSplit&lt;/code&gt;. &lt;code&gt;channelSplit&lt;/code&gt; will take the innerHTML of the element passed as the first argument and clone it 3 times, one for each primary color (red, green and blue).&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see, we are placing a &lt;code&gt;.channel-split-static&lt;/code&gt; span inside the initial element. &lt;code&gt;.channel-split-static&lt;/code&gt; has zero opacity and its use is to preserve the initial dimentions of the text holder element.&lt;/p&gt;

&lt;p&gt;Summarizing the functionality of the &lt;code&gt;channelSplit&lt;/code&gt; function:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Takes one argument, the text holder element&lt;/li&gt;
&lt;li&gt;Clones the innerHTML of the text holder and appends 3 &lt;code&gt;.channel-split&lt;/code&gt; elements, one for each primary color (red, green, blue)&lt;/li&gt;
&lt;li&gt;Places one &lt;code&gt;.channel-split-static&lt;/code&gt; span with zero opacity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We are now done with Javascript 😁!&lt;/p&gt;

&lt;p&gt;Now, all we have to do is to apply some css in order to achieve the desired effect.&lt;/p&gt;

&lt;p&gt;In order to stack each of the three &lt;code&gt;.channel-split&lt;/code&gt; elements one above the other, we set their &lt;code&gt;position&lt;/code&gt; property value to &lt;code&gt;absolute&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Another important change we need to make, is to set &lt;code&gt;mix-blend-mode: difference&lt;/code&gt; to the &lt;code&gt;.channel-split&lt;/code&gt; elements in order to blend their colors. If we don't apply this rule, the final result will display the font color of the elemnt stacked on top of all.&lt;/p&gt;

&lt;p&gt;Here are the main css rules that help us achieve the rgb split effect&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Finally, we are going to apply some animation in order to separately move each of the &lt;code&gt;.channel-split&lt;/code&gt; elements away from each other in order to illustrate the effect.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And that's it!&lt;/p&gt;

&lt;p&gt;Thanks for reading this post and I hope you liked it!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>typography</category>
    </item>
    <item>
      <title>Creating the typewriter effect with the use of async generators</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Mon, 02 Sep 2019 10:14:22 +0000</pubDate>
      <link>https://dev.to/kapantzak/creating-the-typewriter-effect-with-the-use-of-async-generators-5f1e</link>
      <guid>https://dev.to/kapantzak/creating-the-typewriter-effect-with-the-use-of-async-generators-5f1e</guid>
      <description>&lt;p&gt;In this post, we are going to present the process of creating the typewriter effect.&lt;/p&gt;

&lt;p&gt;The following codepen illustrates the final result.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/giannisKapa/embed/ExYwaRL?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Our goal
&lt;/h1&gt;

&lt;p&gt;The functionality we want to achieve is a subset of another library (with more options and methods) called &lt;strong&gt;text-typing&lt;/strong&gt;, that I have developed. It is in beta version yet, but available as npm package for anyone who would like to experiment with some of its capabilities.&lt;/p&gt;

&lt;p&gt;You can find &lt;strong&gt;text-typing&lt;/strong&gt; here:&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/kapantzak" rel="noopener noreferrer"&gt;
        kapantzak
      &lt;/a&gt; / &lt;a href="https://github.com/kapantzak/text-typing" rel="noopener noreferrer"&gt;
        text-typing
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Simple typewriting effect
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a href="https://badge.fury.io/js/text-typing" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/dd67ba60d562113d17fb4f5a0e743f6c97fb565cbf56880a2f6c5a81f3daa4b7/68747470733a2f2f62616467652e667572792e696f2f6a732f746578742d747970696e672e737667" alt="npm version"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;text-typing&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;A tool for creating typewriter effect, with a simple, promise based api.&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/kapantzak/text-typingimg/text-typing.gif?raw=true"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fkapantzak%2Ftext-typingimg%2Ftext-typing.gif%3Fraw%3Dtrue" alt="text-typing gif" title="text-typing"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Install npm package&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;npm&lt;/h4&gt;
&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;npm install text-typing
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;yarn&lt;/h4&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;yarn add text-typing
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And then import the package&lt;/p&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;import {textTyping} from "text-typing";
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Usage&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;All you need to do is to initialize the tool, passing a reference to an existing DOM element, and start typing!&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;HTML&lt;/h4&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;&amp;lt;h1 id="myHeading"&amp;gt;&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;JS&lt;/h4&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;(async () =&amp;gt; {      
  const txt = textTyping(document.getElementById("myHeading"));
  await txt.typeText("Hello");
})();    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;Chaining methods&lt;/h4&gt;

&lt;/div&gt;
&lt;p&gt;You can call multiple methods on the same instance, either by using &lt;code&gt;await&lt;/code&gt; (inside an &lt;code&gt;async&lt;/code&gt; function), or by using &lt;code&gt;then&lt;/code&gt; after a method call&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h5 class="heading-element"&gt;await&lt;/h5&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;(async () =&amp;gt; {      
  const txt = textTyping(elem);
  await txt.typeText("Hello");
  await txt.backspace(2);
})();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h5 class="heading-element"&gt;then&lt;/h5&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;(() =&amp;gt; {
  const txt = textTyping(elem);
  txt.typeText("Hello").then(resp =&amp;gt; {
    resp.backspace(2);
  });
})();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Options&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;speed&lt;/h3&gt;

&lt;/div&gt;
&lt;p&gt;The typing speed that is going to be used by called methods, if no specific speed is provided to the specific method.&lt;/p&gt;
&lt;p&gt;…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/kapantzak/text-typing" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;For this post, we are going to develop a function that exposes a small api (one method 😋) which then, we can call in order to apply the typewriter effect. This function will take two parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The text to be typed&lt;/li&gt;
&lt;li&gt;An array of of two numbers that is going to be used as the speed range of the typing process&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The call is going to be like that:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const textHolder = document.getElementById("myTextHolder");
const speedRange = [100, 600];
const txt = textTyping(textHolder, speedRange);
txt.typeText("Hello there!");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  The markup
&lt;/h1&gt;

&lt;p&gt;For start, we need a HTML element to use it as our text holder. Lets use a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element with id &lt;code&gt;myTextHolder&lt;/code&gt;, nested in another div element that is going to be used as the wrapper element.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Then, we apply some css to verticaly allign our text (not necessary).&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h1&gt;
  
  
  The JS part
&lt;/h1&gt;

&lt;p&gt;We can now begin writing our js functions, starting with the main function that we are goint to call in order to apply the typewriter effect.&lt;/p&gt;

&lt;p&gt;We declare the &lt;code&gt;textTyping&lt;/code&gt; function that takes two arguments&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;elem&lt;/code&gt;: the HTML element to hold the text&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;speedRange&lt;/code&gt;: the speed range that is going to be used&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Blinking cursor
&lt;/h2&gt;

&lt;p&gt;We are developing a typewriting effect, so, we need to display a &lt;strong&gt;blinking cursor&lt;/strong&gt;. For that, we create a &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; element and we apply some css animations in order to achieve the blinking effect.&lt;/p&gt;

&lt;p&gt;We create the cursor as soon as we call the &lt;code&gt;textTyping&lt;/code&gt; function:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;and we apply the respective css:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  API
&lt;/h2&gt;

&lt;p&gt;Now we are going to expose our simple api, which consists of one method, the &lt;code&gt;typeText&lt;/code&gt; method! To achieve that, we return an object that has a property named &lt;code&gt;typeText&lt;/code&gt; and a value of an anonymous function that takes one argument, named &lt;code&gt;text&lt;/code&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In addition, we have added another &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; element (&lt;code&gt;section&lt;/code&gt;) that serves the role of an inner text holder, in order to separate the cursor from the text.&lt;/p&gt;

&lt;h2&gt;
  
  
  Typing process
&lt;/h2&gt;

&lt;p&gt;Now we have to implement the typing process. Lets try by spliting the text and getting an array of letters. We can iterate this array and insert each letter inside the &lt;code&gt;section&lt;/code&gt; element one by one.&lt;/p&gt;

&lt;p&gt;Furthermore, we need to inject a timeout before each letter injection, based on the speedRange parameter provided to &lt;code&gt;textTyping&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Lets declare a function that takes the &lt;code&gt;speedRange&lt;/code&gt; array and returns a random number inside the two numbers contained in the array:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here is our first (&lt;strong&gt;not successful&lt;/strong&gt;) attempt&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/giannisKapa/embed/bGboVGK?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;What happened? Why are letters mixed up?&lt;/p&gt;

&lt;p&gt;The problem is here&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;for&lt;/code&gt; loop instantly iterates the letters array and the &lt;code&gt;setTimeout&lt;/code&gt; callbacks start to execute at a random time from the loop execution end.&lt;/p&gt;

&lt;p&gt;Each &lt;code&gt;setTimeout&lt;/code&gt; does not wait for the previous timeout callback to be called, as javascript has a non-blocking runtime. On the contrary, each &lt;code&gt;setTimeout&lt;/code&gt;, instantly pushes a callback to the message queue with a random timeout generated by &lt;code&gt;getSpeed&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;For more details about asynchronous execution, you can checkout this article about the event loop.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/kapantzak" 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%2F203745%2F4a0fb7e4-0cfc-4bf0-ae7e-baa0d93e720b.jpeg" alt="kapantzak"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kapantzak/js-illustrated-the-event-loop-4mco" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JS illustrated: The event loop 🔁&lt;/h2&gt;
      &lt;h3&gt;John Kapantzakis ・ Aug 15 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Async generators
&lt;/h2&gt;

&lt;p&gt;In order to solve our problem, we need to find a way to, correctly iterate over a  sequence of asynchronous tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Async generators&lt;/strong&gt; come to our resque!&lt;/p&gt;

&lt;p&gt;We are not going to get into more detail about async generators or async iterators. For now, we only need to know that async generators provide us with the ability to generate sequences of asynchronous data, that can be iterated and procude the desired outcome.&lt;/p&gt;

&lt;p&gt;Now lets apply them to our function.&lt;/p&gt;

&lt;p&gt;First, we need to declare a function that returns a &lt;strong&gt;Promise&lt;/strong&gt; which gets resolved after a certain amount of time, returning the appropriate letter for us.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We are going to call this function inside our async generator as shown in the following gist:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Note the &lt;code&gt;function*&lt;/code&gt; statement, this is the way we declare generators. And because we want an async generator, we prepend the &lt;code&gt;async&lt;/code&gt; keyword (in fact &lt;code&gt;async&lt;/code&gt; is not a keyword itself, instead, the combination &lt;code&gt;async function&lt;/code&gt; is).&lt;/p&gt;

&lt;p&gt;All we have to do now is to iterate over the sequence that our async generator produces. We can do that with the use of the &lt;code&gt;for await ... of&lt;/code&gt; statement like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We now have the desired result, as shown in the codepen at the begining of the post.&lt;/p&gt;

&lt;p&gt;Thanks for reading 🤗 so far! I hope it was interesting enough! Please leave your comments for any feedback or questions!&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript.info/async-iterators-generators" rel="noopener noreferrer"&gt;https://javascript.info/async-iterators-generators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jakearchibald.com/2017/async-iterators-and-generators/" rel="noopener noreferrer"&gt;https://jakearchibald.com/2017/async-iterators-and-generators/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/wrI-Jb0oFyk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>async</category>
      <category>generator</category>
      <category>typewriter</category>
    </item>
    <item>
      <title>Using Redux in a legacy ASP.NET Web Forms project</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Thu, 22 Aug 2019 07:36:49 +0000</pubDate>
      <link>https://dev.to/kapantzak/using-redux-in-a-legacy-asp-net-web-forms-project-1805</link>
      <guid>https://dev.to/kapantzak/using-redux-in-a-legacy-asp-net-web-forms-project-1805</guid>
      <description>&lt;p&gt;&lt;a href="https://redux.js.org/" rel="noopener noreferrer"&gt;Redux&lt;/a&gt; is an implementation of Facebook's &lt;a href="https://facebook.github.io/flux/" rel="noopener noreferrer"&gt;Flux&lt;/a&gt; design pattern.&lt;/p&gt;

&lt;p&gt;Someone might say &lt;em&gt;"Why use Redux in other than a React app?"&lt;/em&gt;. It may seems a little strange now, but it helped my team to organize the data flow.&lt;/p&gt;

&lt;p&gt;In my current job, I am involved in a project built in &lt;a href="https://docs.microsoft.com/el-gr/aspnet/web-forms/what-is-web-forms" rel="noopener noreferrer"&gt;ASP.NET Web Froms&lt;/a&gt; technology. It is a quite old fashioned technology but we have tried to use some modern tools , like &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;Typescript&lt;/a&gt; and &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;webpack&lt;/a&gt;, in order to improve the development process.&lt;/p&gt;

&lt;h1&gt;
  
  
  Application overview
&lt;/h1&gt;

&lt;p&gt;The application uses a &lt;strong&gt;Master Page&lt;/strong&gt;, which is the entry point and loads the appropriate &lt;strong&gt;User Control&lt;/strong&gt;, depending on the url.&lt;/p&gt;

&lt;p&gt;Each user control (from now on, we will call it a &lt;em&gt;form&lt;/em&gt;) loads the respective javascript file which handles the client's interactions.&lt;/p&gt;

&lt;p&gt;The communication with the server is happening via ajax calls to specific files with the &lt;code&gt;.ashx&lt;/code&gt; extension (&lt;em&gt;Generic Handlers&lt;/em&gt;), althoug there are some cases that a postback is triggered, causing a full refresh of the page.&lt;/p&gt;

&lt;p&gt;Here's a simple overview&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%2Fzzf8sraxf4sutgw6gtfq.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%2Fzzf8sraxf4sutgw6gtfq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The problem
&lt;/h1&gt;

&lt;p&gt;In our project, it is a common case that a form has some filters (Kendo controls), an &lt;em&gt;Apply filters&lt;/em&gt; button and a grid that displays the results.&lt;/p&gt;

&lt;p&gt;Lets say that we have a form with 3 filters, a combobox for the available departments, a combobox for the employees and a textbox for some comments.&lt;/p&gt;

&lt;p&gt;On load, each of these filters is getting some initial data. The two comboboxes get a list of departments and a list of employees, respectively, while the comments textbox gets a string. These datasources have to be retrieved from the database and be strored in some hidden fields on the backend.&lt;/p&gt;

&lt;p&gt;On the frontend, on &lt;code&gt;window.load&lt;/code&gt;, the Kendo controls get initialized with the hidden field's values as the datasources.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function initFilters() {
    const departments = JSON.parse($('#Hidden_departments').val());
    const employees = JSON.parse($('#Hidden_employees').val());
    const comments = $('#Hidden_comments').val();

    $('#cmb_departments').kendoDropDownList({
        data: departments
    });

    // Same for others ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We can see that each filters gets its datasource from a different point.&lt;/p&gt;

&lt;p&gt;The same happens when we want to gather the filters values and submit them to the server. We, again, have to search in different places to get each value, create an object with these values and send it to the server.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getFiltersValues() {
    const departmentVal = $('#cmb_departments').data('kendoDropDownList').value();
    const employeeVal = $('#cmb_employees').data('kendoDropDownList').value();
    const commentsVal = $('#txt_comments').val();

    return {
        department: departmentVal,
        employee: employeeVal,
        comments: commentsVal
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The following diagram illustrates the above process.&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%2Fch4mps5by6evo49uhmxa.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%2Fch4mps5by6evo49uhmxa.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, the problem is that we have to search in many different places in order to get the filters datasources and the filters values, in a sentence:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There isn't a single source of truth!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1&gt;
  
  
  Using Redux
&lt;/h1&gt;

&lt;p&gt;As opposed to the previous approach, with Redux, we try to maintain a single source of truth. This source is the application state, or better, the user control state, because each user control maintains its own state (we do not implement a universal application state, instead, we treat each user control as a &lt;strong&gt;separate application&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;The following diagram illustrates the user control's data lifecycle:&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%2Fleecx8km3etywhhn3xn0.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%2Fleecx8km3etywhhn3xn0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Implementation
&lt;/h1&gt;

&lt;p&gt;Now, lets see how we use Redux in our ASP.NET Web Forms project.&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%2Fs7nnyk2ahge90krbdopw.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%2Fs7nnyk2ahge90krbdopw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Initial state
&lt;/h3&gt;

&lt;p&gt;As the user control loads, the backend (&lt;code&gt;.ascx.cs&lt;/code&gt;) queries the database, creates an object that represents the initial state, serializes it and stores it in a hidden field.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  Reducers
&lt;/h3&gt;

&lt;p&gt;Before initializing the store object in the &lt;code&gt;.ts&lt;/code&gt; file, we have to create some &lt;a href="https://redux.js.org/basics/reducers" rel="noopener noreferrer"&gt;reducers&lt;/a&gt; and some &lt;a href="https://redux.js.org/basics/actions" rel="noopener noreferrer"&gt;actions&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Create store
&lt;/h3&gt;

&lt;p&gt;The user control loads a specific javascript file which initializes a &lt;a href="https://redux.js.org/api/store" rel="noopener noreferrer"&gt;Redux store&lt;/a&gt;. We have imported the &lt;code&gt;appReducer&lt;/code&gt; from the &lt;code&gt;stateHelper.ts&lt;/code&gt; file and we use it to initialize the store.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;After getting the initial state, we can build the ui using the data from our single source of truth, the store!&lt;/p&gt;

&lt;h3&gt;
  
  
  Updating the state
&lt;/h3&gt;

&lt;p&gt;While having a store object available, we can dispatch the actions declared in the &lt;code&gt;stateHelper.ts&lt;/code&gt; anywhere we want, inside our &lt;code&gt;page.ts&lt;/code&gt; file.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Any time we dispatch an action, the reducer returns an updated &lt;strong&gt;copy&lt;/strong&gt; of our application state. The state itself should &lt;strong&gt;never be mutated&lt;/strong&gt; according to Flux pattern.&lt;/p&gt;

&lt;h3&gt;
  
  
  Saving data
&lt;/h3&gt;

&lt;p&gt;Now that we have a single source of truth, it is very easy to submit our data to the server. We just have to get the most recent verion of the application state and send it to the generic handler, which, in turn, saves the data to the database.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Despite the relative complexity and steep learing curve, Redux proved to be a helpful tool for our team. Here are some pros and cons that came out of Redux use:&lt;/p&gt;

&lt;h3&gt;
  
  
  👍 Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Provides a single point of truth&lt;/li&gt;
&lt;li&gt;Use of functional paradigm principles (immutable data, pure functions etc)&lt;/li&gt;
&lt;li&gt;Quick addition / removal of ui controls without unwanted side effects&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  👎 Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Overkill for small apps&lt;/li&gt;
&lt;li&gt;Steep learing curve (depends on the developer's experiense)&lt;/li&gt;
&lt;li&gt;Initial setup requires some time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It seems that Redux can be used in other than React applications too. If you have  similar experiense you may want to drop your comments!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>redux</category>
      <category>aspnet</category>
      <category>webforms</category>
    </item>
    <item>
      <title>Waiting for visible element</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Mon, 19 Aug 2019 13:07:14 +0000</pubDate>
      <link>https://dev.to/kapantzak/waiting-for-visible-element-4ck9</link>
      <guid>https://dev.to/kapantzak/waiting-for-visible-element-4ck9</guid>
      <description>&lt;p&gt;Sometimes we need to call a function when a specific element is visible.&lt;/p&gt;

&lt;p&gt;We might  want to load something that is going to calculate its dimensions based on its parent element's dimensions.&lt;/p&gt;

&lt;p&gt;I, my self, have been in this position, trying to trigger a plugin init function when a specific area is visible (or, better, when this area has dimensions).&lt;/p&gt;

&lt;p&gt;This is a solution I've came up with:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;waitVisible&lt;/code&gt; function will call a given function, as soon as the specified element gets visible.&lt;/p&gt;

&lt;p&gt;It takes 3 arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The element we want to check upon&lt;/li&gt;
&lt;li&gt;The callback function that we want to be executed when the element gets visible&lt;/li&gt;
&lt;li&gt;The maximum amount of time that the function is going to check for the element's visibility (default: 5000 ms)&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Example (Google charts)
&lt;/h1&gt;

&lt;p&gt;Let say that we want to display a pie chart (example &lt;a href="https://google-developers.appspot.com/chart/interactive/docs/gallery/piechart"&gt;here&lt;/a&gt;) inside a div that is not initially visible.&lt;/p&gt;

&lt;p&gt;First, we call the &lt;code&gt;drawChart&lt;/code&gt; function as soon as the Google charts script loads.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;google.charts.setOnLoadCallback(drawChart);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you check the &lt;em&gt;Result&lt;/em&gt; tab on the fiddle below, you can see that the chart is placed on the left side (when viewing in a relatively wide screen), taking as little space as it can in order to be displayed.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/kapantzak/eqwbzov5/23//embedded//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Here, we use &lt;code&gt;waitVisible&lt;/code&gt; to call the &lt;code&gt;drawChart&lt;/code&gt; function. The &lt;code&gt;drawChart&lt;/code&gt; is able to calculate its parent eleemnt's dimensions and the chart takes up all the available width as you can see in the next fiddle:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/kapantzak/t8no1xm2/3//embedded//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That's my solution to this problem. If you want to propose something else, please feel free to comment!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>dom</category>
    </item>
    <item>
      <title>JS illustrated: The event loop 🔁</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Thu, 15 Aug 2019 23:00:21 +0000</pubDate>
      <link>https://dev.to/kapantzak/js-illustrated-the-event-loop-4mco</link>
      <guid>https://dev.to/kapantzak/js-illustrated-the-event-loop-4mco</guid>
      <description>&lt;p&gt;Javascript is single threaded, yet, developers can write asynchronous code in Javascript!&lt;/p&gt;

&lt;p&gt;But how is it possible? The event loop makes it possible!&lt;/p&gt;

&lt;p&gt;Before we start, lets define the environment in which the event loop operates. We assume that we are dealing with Javascript code that is executed by a browser (not in Node or other environment).&lt;/p&gt;

&lt;p&gt;Lets meet the heros of our story&lt;/p&gt;

&lt;h1&gt;
  
  
  The call stack
&lt;/h1&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%2Fvt1lq8dr1xnia6p2u9cp.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%2Fvt1lq8dr1xnia6p2u9cp.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The call stack is a place in memory that keeps track of the function executing at that time, and the functions that are going to be executed after that. Each function is placed on top of the previous function. The first function added, is going to be executed last (First in, last out).&lt;/p&gt;

&lt;h1&gt;
  
  
  The web API
&lt;/h1&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%2Fvuqg7xfop4hy8bvw3hu1.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%2Fvuqg7xfop4hy8bvw3hu1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The web API is not part of the core JS, instead, it provides various methods that can be used by a Javascript program, like &lt;code&gt;setTimeout()&lt;/code&gt; or &lt;code&gt;alert()&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  The message queue
&lt;/h1&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%2Ft7p6bgzqu9q3h5j5gmsh.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%2Ft7p6bgzqu9q3h5j5gmsh.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The message queue is a list of messages, waiting to be executed by their associated functions. A new message is added to the list, each time an event, that has been watched by an event listener, occures.&lt;/p&gt;

&lt;h1&gt;
  
  
  The event loop
&lt;/h1&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%2Fjr8h8zb75ultqptp3r5o.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%2Fjr8h8zb75ultqptp3r5o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The event loop is a process that keeps running and checks whether the call stack is empty or not. If the call stack is empty, it pushes the first item of the message queue into the call stack for execution.&lt;/p&gt;

&lt;p&gt;Here's the browser environment&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%2Fuge9s4sxw8f2tf5nbjz6.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%2Fuge9s4sxw8f2tf5nbjz6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  A JS story
&lt;/h1&gt;

&lt;p&gt;Lets take a look at the following code and see what happens&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Calling the &lt;code&gt;foo&lt;/code&gt; function, the result is&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; One
&amp;gt; Three
&amp;gt; Two
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, lets see our heros trying to execute the above code&lt;/p&gt;

&lt;p&gt;First, the browser sends the &lt;code&gt;foo()&lt;/code&gt; function call to the call stack.&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%2Fo48tslf0jdmadl13cvcn.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%2Fo48tslf0jdmadl13cvcn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;console.log("One")&lt;/code&gt; statement gets pushed on top of the previous frame.&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%2F0t69b2ogj37gkoaqusf1.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%2F0t69b2ogj37gkoaqusf1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the meanwhile, the event loop checks to see if the call stack is empty&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%2F65sj3txo63lvhnh6rotx.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%2F65sj3txo63lvhnh6rotx.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The JS runtime executes the top frame and removes it from the call stack.&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%2Fwlgm90neatktrds37jok.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%2Fwlgm90neatktrds37jok.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Continuing the execution, the browser sends the &lt;code&gt;setTimeout()&lt;/code&gt; statement to the stack&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%2Fo9ffcy95t6gl1rq1qrzk.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%2Fo9ffcy95t6gl1rq1qrzk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The event loop checks again&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%2Focd9j7fhuptra2q8kb9o.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%2Focd9j7fhuptra2q8kb9o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The environment sets up a timer that is going to trigger the callback inside the &lt;code&gt;setTimeout&lt;/code&gt;&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%2Ftbre7v5gfg1zoiam0dw8.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%2Ftbre7v5gfg1zoiam0dw8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and the next statement is pushed into the call stack&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%2Fo007pzbfjrgbnavxuiel.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%2Fo007pzbfjrgbnavxuiel.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's the event loop again&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%2Fzekyensfo6431nsjn6fw.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%2Fzekyensfo6431nsjn6fw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The event loop did not find an empty stack so it does nothing again. The execution continues with the next, and final, statement of the &lt;code&gt;foo()&lt;/code&gt; function&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%2Feo7g60avq4bugbu8fqqk.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%2Feo7g60avq4bugbu8fqqk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets get back to the web API, which set up a timer for a callback function. Now that the timer has ended, the browser sends the callback message to the message queue&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%2Ff9upsh1ul4z9jwfp4qy9.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%2Ff9upsh1ul4z9jwfp4qy9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the last statement got executed, it is removed from the stack, and, as soon as there is nothing else inside the &lt;code&gt;foo()&lt;/code&gt; function declaration, the oldest &lt;code&gt;foo()&lt;/code&gt; frame is removed from the call stack too!&lt;/p&gt;

&lt;p&gt;Now, the event loop may be more lucky&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%2Fhga1ny4nb18v07nu7zkt.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%2Fhga1ny4nb18v07nu7zkt.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The event loop checks for any messages waiting in the queue&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%2F3z0tsghi3nj32nmaloxw.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%2F3z0tsghi3nj32nmaloxw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and sends the message's associated function to the call stack&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%2Fqso2vz6qwnav0ty1kuhq.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%2Fqso2vz6qwnav0ty1kuhq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, the JS runtime executes the last frame and removes it form the call stack&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%2F7iwx5zisofb9ffoqg17c.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%2F7iwx5zisofb9ffoqg17c.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop" rel="noopener noreferrer"&gt;MDN: Concurrency model and Event Loop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hackernoon.com/understanding-js-the-event-loop-959beae3ac40" rel="noopener noreferrer"&gt;Hackernoon: Understanding JS: The Event Loop (Alexander Kondov)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/front-end-weekly/javascript-event-loop-explained-4cd26af121d4" rel="noopener noreferrer"&gt;Medium: JavaScript Event Loop Explained (Anoop Raveendran
)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/You-Dont-Know-JS-Performance/dp/1491904224" rel="noopener noreferrer"&gt;Kyle Simpson, 2015, &lt;em&gt;You don't know JS: Async &amp;amp; Performance&lt;/em&gt;, 5-7&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Some of my favorite Javascript resources</title>
      <dc:creator>John Kapantzakis</dc:creator>
      <pubDate>Tue, 06 Aug 2019 21:45:47 +0000</pubDate>
      <link>https://dev.to/kapantzak/some-of-my-favorite-javascript-resources-13cg</link>
      <guid>https://dev.to/kapantzak/some-of-my-favorite-javascript-resources-13cg</guid>
      <description>&lt;p&gt;This is my first post here in dev.to, so I think I'm going to start with a presentation of some of my favorite Javascript resources!&lt;/p&gt;

&lt;h1&gt;
  
  
  The Modern JavaScript Tutorial
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5UXZouzm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6p0d8dmupzte1e7x3twm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5UXZouzm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6p0d8dmupzte1e7x3twm.jpg" alt="" width="880" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first resource I'm going to present is an online tutorial by Ilya Kantor (and many other contributors on Github). It is a simple tutorial that covers lots of the language's aspects. It is organized in three main parts:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The JavaScript language
&lt;/h3&gt;

&lt;p&gt;Here, the author starts with an introduction to the language, proceeds with the basic building blocks, like data types, conditional and logical operators, loops, functions, prototypes, classes etc, and ends with more advanced topics like, promises, generators, the module pattern etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Browser: Document, Events, Interfaces
&lt;/h3&gt;

&lt;p&gt;The second part is dedicated to browsers and working with the DOM. Elements, events, event listeners, forms, are some of the topics that this part is dealing with.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Additional articles
&lt;/h3&gt;

&lt;p&gt;In the third part, the author presents a set of various articles that cover topics that were not covered in the previous parts of the tutorial, like these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frames and windows&lt;/li&gt;
&lt;li&gt;Binary data and files&lt;/li&gt;
&lt;li&gt;Network requests&lt;/li&gt;
&lt;li&gt;Animations&lt;/li&gt;
&lt;li&gt;Regular expressions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and more..&lt;/p&gt;

&lt;p&gt;I found this tutorial very useful and easy to follow. The author has a unique way of explaining each topic with simple examples that makes it easy for the reader to get the point. Furthermore, the structure of the tutorial allows for easy and quick search of anything! I often consult this tutorial for various topics and I would encourage anyone to do so 😀&lt;/p&gt;

&lt;h1&gt;
  
  
  Fun Fun Function
&lt;/h1&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/2d7s3spWAzo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Another resource that I would like to present is the &lt;strong&gt;Fun Fun Function&lt;/strong&gt; channel on YouTube, by Mattias Petter Johansson (or &lt;em&gt;mpg&lt;/em&gt;). In this channel, Mattias releases a new video every Monday at 08:00 GMT, resulting in a great teaching experience! Various topics are covered here like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functional programming&lt;/li&gt;
&lt;li&gt;Closures&lt;/li&gt;
&lt;li&gt;Currying&lt;/li&gt;
&lt;li&gt;Transducers&lt;/li&gt;
&lt;li&gt;TDD&lt;/li&gt;
&lt;li&gt;Promises / Async-Await / Generators&lt;/li&gt;
&lt;li&gt;GraphQL&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;li&gt;Classes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and so much more, such as more abstract topic like &lt;em&gt;Time to leave your job?&lt;/em&gt;, &lt;em&gt;Problem solving preparation&lt;/em&gt; etc.&lt;/p&gt;

&lt;p&gt;As with the previous resource, Mattias is excellent in explaining advanced topics in a clean and understandable way, with a lot humor! &lt;strong&gt;Fun Fun Function&lt;/strong&gt; episodes helped me underdestand promises, generators, iterators and functional programming principles.&lt;/p&gt;

&lt;h1&gt;
  
  
  Eric Elliot - Medium Blog
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vaVoOMZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1bow6zr3ab53u9nwmmor.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vaVoOMZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1bow6zr3ab53u9nwmmor.jpg" alt="" width="798" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Eric Elliot is the author of &lt;a href="https://www.amazon.com/Programming-JavaScript-Applications-Architecture-Libraries/dp/1491950293/ref=as_li_ss_tl?ie=UTF8&amp;amp;qid=1501725815&amp;amp;sr=8-1&amp;amp;keywords=programming+javascript+applications&amp;amp;linkCode=ll1&amp;amp;tag=eejs-20&amp;amp;linkId=c45c264a109e67af7ecfe5ef2856da63"&gt;Programming JavaScript Applications&lt;/a&gt; and &lt;a href="https://medium.com/javascript-scene"&gt;JavaScript Scene&lt;/a&gt;. His blog in Medium covers a wide range of Javascript topics in great detail.&lt;/p&gt;

&lt;p&gt;Some of the articles that I've read and I liked the most are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-pure-function-d1c076bec976"&gt;Master the JavaScript Interview: What is a Pure Function?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/javascript-scene/transducers-efficient-data-processing-pipelines-in-javascript-7985330fe73d"&gt;Transducers: Efficient Data Processing Pipelines in JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/javascript-scene/curry-and-function-composition-2c208d774983"&gt;Curry and Function Composition&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Eric Elliot's articles helped me take a deep dive into some of the core concepts of the functional paradigm (like currying, pure functions, tranducers etc). It is obvious that Eric has a deep knowledge of the Javascript language. This is reflected in his articles, each of which constitutes a profound and valid analysis of the topic under investigation. I will definitely try to find the time to read all of his posts!&lt;/p&gt;

&lt;h1&gt;
  
  
  Programming Javascript Applications by Eric Elliot
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hiUy93yA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mwrz14xknkpf3w30775o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hiUy93yA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mwrz14xknkpf3w30775o.jpg" alt="" width="305" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am going to stick with Eric Elliot for the next resource, as it is a book that presents a complete overview of a modern Javascript application architecture. This book covers various topics like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Presentation of the Javascript language and its advantages&lt;/li&gt;
&lt;li&gt;Functions (pure functions, lambdas, IIFE, scope, hoisting etc)&lt;/li&gt;
&lt;li&gt;Objects (Prototypes vs OOP)&lt;/li&gt;
&lt;li&gt;Modules (AMD, ES6 modules)&lt;/li&gt;
&lt;li&gt;Client side vs server side&lt;/li&gt;
&lt;li&gt;Authentication and authorization&lt;/li&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;REST APIs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and much more, all with detailed examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Programming Javascript Applications&lt;/strong&gt; helped me get a full picture of how modern Javascript applications should be organized, tested and deployed.&lt;/p&gt;

&lt;h1&gt;
  
  
  You don't know JS by Kyle Simpson
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XF2vaOI8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mmreawa43gitts6gkdqi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XF2vaOI8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mmreawa43gitts6gkdqi.jpg" alt="" width="800" height="614"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last but not least (in fact that's my favorite), it's a series of 6 books by Kyle Simpson, titled &lt;em&gt;You don't know JS&lt;/em&gt;. &lt;a href="https://me.getify.com/"&gt;Kyle Simpson&lt;/a&gt; teaches Javascript and he is realy good at that! Seriously, I believe Javascript is what it runs into his veins!&lt;/p&gt;

&lt;p&gt;The series consists of six books and is suggested that they are read in the following order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Up &amp;amp; Going&lt;/li&gt;
&lt;li&gt;Scope &amp;amp; Closures&lt;/li&gt;
&lt;li&gt;this &amp;amp; Object Prototypes&lt;/li&gt;
&lt;li&gt;Types &amp;amp; Grammar&lt;/li&gt;
&lt;li&gt;Async &amp;amp; Performance&lt;/li&gt;
&lt;li&gt;ES6 &amp;amp; Beyond&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What I liked the most in this book series, is the author's absolutely deep knowledge of the subject. Kyle Simpson shows that he takes seriourly what he does and that made me love his way of writing.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;After reading those books and watching many videos, alongside with other useful resources, not mentioned in this post, I retook a pluralsight skill assessment in Javascript and managed to reach the expert level. It seems that these resources were really useful to me, and I hope for you too!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nbYrziGQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dwvf4txpp39ye2kcyzmc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nbYrziGQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dwvf4txpp39ye2kcyzmc.jpg" alt="" width="669" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please, let me know what do you think about the resources I presented. Feel free to list some of your favorite books, tutorials, or anything else!&lt;/p&gt;

&lt;h1&gt;
  
  
  Future reading
&lt;/h1&gt;

&lt;p&gt;Here are some resources that I would like to read in the future:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://leanpub.com/composingsoftware"&gt;Composing Software&lt;/a&gt; (by Eric Elliot)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.com/Testable-JavaScript-Ensuring-Reliable-Code/dp/1449323391"&gt;Testable JavaScript: Ensuring Reliable Code&lt;/a&gt; (by Mark Ethan Troster)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/getify/Functional-Light-JS"&gt;Functional Light JS&lt;/a&gt; (by Kyle Simpson)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.oreilly.com/library/view/learning-javascript-design/9781449334840/"&gt;Learning Javascript Design Patterns&lt;/a&gt; (by Addy Osmani)&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://javascript.info/"&gt;The Modern JavaScript Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/channel/UCO1cgjhGzsSYb1rsB4bFe4Q/featured"&gt;Fun Fun Function&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@_ericelliott"&gt;Eric Elliot - Medium&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Programming-JavaScript-Applications-Architecture-Libraries/dp/1491950293"&gt;Programming Javascript Applications&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/gp/product/B07FK9VBD7/?ie=UTF8&amp;amp;%2AVersion%2A=1&amp;amp;%2Aentries%2A=0"&gt;You don't know JS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>books</category>
      <category>tutorial</category>
      <category>opinion</category>
    </item>
  </channel>
</rss>
