<?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>Forem: Łukasz Żarski</title>
    <description>The latest articles on Forem by Łukasz Żarski (@lukaszzarski).</description>
    <link>https://forem.com/lukaszzarski</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%2F140476%2F130a4281-743b-4653-bf52-844aa07649c4.jpg</url>
      <title>Forem: Łukasz Żarski</title>
      <link>https://forem.com/lukaszzarski</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lukaszzarski"/>
    <language>en</language>
    <item>
      <title>Trailblazer is back, better then ever!</title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Fri, 03 Jul 2020 13:09:49 +0000</pubDate>
      <link>https://forem.com/2nit/trailblazer-is-back-better-then-ever-37nm</link>
      <guid>https://forem.com/2nit/trailblazer-is-back-better-then-ever-37nm</guid>
      <description>&lt;p&gt;For those who know Trailblazer - you know that for the last 6 years TRB evolved a few times, introduced a lot of great ideas but also had it's problems: missing documentation, lack of communication with the community, and inconsistent approach to some problems. We strongly believe the current version, along with the support of the core team and the new landing page (with complete documentation) is worth working with.&lt;/p&gt;

&lt;p&gt;For those who somehow haven't hear about Trailblazer - check it out. Probably for some complex projects where Rails aren't sufficient that tool could be really helpful and efficent.&lt;/p&gt;

&lt;p&gt;The main changes coming with the new version of TRB relate to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Major API change,&lt;/li&gt;
&lt;li&gt;Autoloading,&lt;/li&gt;
&lt;li&gt;New website with complete documentation,&lt;/li&gt;
&lt;li&gt;Tracing.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;The updated version 2.1 contains some necessary and sound improvements in the method signatures. One of these changes is the replacement of the automatic merging of &lt;code&gt;params&lt;/code&gt; part and additional options with the possibility to pass one hash to the &lt;code&gt;call&lt;/code&gt; and do the merging. Second major change in API is that &lt;code&gt;ctx&lt;/code&gt; elements are now accessible both as strings and symbols like in a hash. It’s worth noticing that &lt;code&gt;ctx&lt;/code&gt; object is now documented in its own section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# old style
result = Memo::Create.(params, "current_user" =&amp;gt; current_user)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# new style
result = Memo::Operation::Create.(params: params, current_user: current_user)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  AUTOLOADING
&lt;/h2&gt;

&lt;p&gt;The significant change to autoloading is return to Rails file and class naming structure for &lt;strong&gt;operations&lt;/strong&gt;. This change allowed removing the &lt;code&gt;trailblazer-loader&lt;/code&gt; gem, which was responsible for causing some issues and inconsistencies. &lt;/p&gt;

&lt;h2&gt;
  
  
  NEW WEBSITE
&lt;/h2&gt;

&lt;p&gt;The goal behind creating a new website was to make it as simple as possible. A lot of pages accessible through the top navigation, and then the documentation behind the DOCS link.&lt;/p&gt;

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

&lt;p&gt;The documentation has been structured in such a way as to ensure the fastest possible access to consistent information. There's even added a new search function - something that TRB user base has repeatedly asked for. Just press the / (or Shift+7) button in the docs.&lt;/p&gt;

&lt;h2&gt;
  
  
  TRACING
&lt;/h2&gt;

&lt;p&gt;The 2.1 version comes with the ability to track the operations - something that was missing in all the prior releases. This change makes debugging deeply nested operations way more pleasant. &lt;/p&gt;

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

&lt;p&gt;Either you know TRB already or you never heard about it, check out the &lt;a href="https://trailblazer.to/2.1/blog.html"&gt;blog post about the history and changes of trailblazer 2.1&lt;/a&gt; and give the core team some feedback!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
    </item>
    <item>
      <title>The Art of Project Management - part 2</title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Thu, 14 May 2020 11:34:20 +0000</pubDate>
      <link>https://forem.com/2nit/the-art-of-project-management-part-2-37k6</link>
      <guid>https://forem.com/2nit/the-art-of-project-management-part-2-37k6</guid>
      <description>&lt;h2&gt;
  
  
  INTRODUCTION
&lt;/h2&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/2nit/the-art-of-project-management-4ed2"&gt;first part of the cycle&lt;/a&gt;, we talked about initial estimations (in our case project concept) and characteristics of a good leader based on the first chapter of Sun Tzu’s TAoW. Since we established that the preparation for the upcoming new challenges is crucial in terms of accomplishing success, we can now move to adopt a strategy and adjust tactics to our situation while still focusing on our ancient guidance. So let’s try to examine in this light the second and third TAoW chapters!&lt;/p&gt;

&lt;h2&gt;
  
  
  Waging War - Strategy
&lt;/h2&gt;

&lt;p&gt;The second chapter of TAoW is focusing solely on a concept of waging war, estimating available resources, and how to avoid weakening your army by running out of them. Of course, we don’t have to gather a thousand swift chariots or a hundred thousand mail-clad soldiers, thankfully. Nevertheless, we have to be able to predict how many resources will be needed to complete our campaign - we need to create a project cost estimation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"He who wishes to fight must first count the cost"&lt;/em&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%2F74al4c7rfeun49io921u.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F74al4c7rfeun49io921u.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The key to estimating it properly is to prepare beforehand, just like we said in the previous part. The knowledge of what to expect is crucial. It allows us to evaluate how many troops we need to assign for the whole operation and also how to provide for their subsistence. In our case, the base of estimation should be an in-depth discussion with our client. It’s not uncommon that our customer can table indispensable cornerstones of the project that are reasonable, but it’s getting harder for him to describe the smaller elements that might not seem important at first sight (or even unnoticeable). It’s our job to extract as much information as possible, mainly by asking a lot of questions. Those questions are intended to enable us to better understand his expectations and the amount of work that will be required. It’s worth keeping in mind that this estimation won’t be certain. It’s more about predicting the cost than counting the actual cost.&lt;/p&gt;

&lt;p&gt;After getting all the information that we could get from our client, we could now prepare some scenarios of how using the actual app would look like. I mean, of course, well-known user stories. Those are short descriptions of functionality told from the user's perspective - user cases. The idea behind them is to organize work - basing on them it is easier to section off smaller parts of tasks from the entirety of a project. &lt;em&gt;“Ok, but why are user stories important while estimating resources?”&lt;/em&gt; - you might ask. Well, I believe that they allow specifying all of the moving parts within a project, their inner connections, and the order of completion. They help to ensure that none of the aspects of a project are overlooked and every one of them is properly tested. From the customer’s perspective, those initial user stories could be helpful after the project is given to him, simply because he can recreate any of them to find out if requested features are present and are working as they should be.&lt;/p&gt;

&lt;p&gt;But user stories are not everything we need to prepare accurate estimations for - we need to go deeper. For example, one of our use cases could be the need to log in to the app by our user. It’s pretty simple, right? But what has to be done to make this possible while making it a pleasant experience? It’s required to design the UX interface, prepare the graphic design of the site, and implement code responsible for the validation of data put by the user in the given fields (at least). So basically we have to divide all of the use cases for smaller tasks and THEN we can think about estimating one case after another. This approach allows us to make predictions that are closest to reality. Without focusing on all the smallest factors it’s possible, that we could draw our estimations right out of the hat as well. &lt;/p&gt;

&lt;p&gt;As I said in the previous part of the cycle, we can also align ourselves by using different methods like building BPMN diagrams or creating a schema of the project. Finding the right tools shouldn’t be a problem - there are already plenty of them all over the Internet, and many more still emerging (just like &lt;a href="https://graphqleditor.com" rel="noopener noreferrer"&gt;GraphQL Editor&lt;/a&gt; mentioned in a previous post  for creating GraphQL schema, documenting it etc.).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://graphqleditor.com" rel="noopener noreferrer"&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%2Fkb1ugj81fuoaovhlkm7i.gif" alt="GraphQL Editor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But even if we manage to prepare a lot of information and ancillary materials there is always a risk of a huge under/overestimation. It’s a human factor. That’s why it is always safer to go through initial estimation with other members of your team. Sure, the estimation of every task won’t need to be double-checked but look from other perspectives will allow us to minimize the aforementioned risk.  &lt;/p&gt;

&lt;p&gt;All of the above sound nice and easy, right? Almost ideal. It is, but it requires almost ideal conditions as well - time and budget, that could be strictly limited. For example, our client knows what he wants from his potential app, but has little to none idea what should this app contain and how to execute this. On the other hand, he seeks to apply for donation and there are just a few days left to present the cost predictions to the granter. &lt;br&gt;
So what when the customer that wants to engage in a project does not have enough time or other factors are in the way of preparing complex estimation? Well, assuming that our customer has limited resources, skipping estimation altogether would be a mistake because it could lead to stretching his budget a lot in the future and not meeting the set deadlines. Instead, we could make use of our experiences with other projects and try to guide our customers with propositions based on them. A whole lot of projects have some similarities.&lt;/p&gt;

&lt;p&gt;Let’s take the previous example of a user's login into an app - that’s pretty common so most PMs and their team members know how to handle that. The same goes for things like online payments, placing an order, etc. Using those experiences might let us focus more on unique parts of the project while not letting those other parts slow our progress down. &lt;/p&gt;

&lt;p&gt;But it is possible to make the process of estimating simpler and shorter. It won’t be as accurate of course, but it will give us the overall picture. In this scenario, it is very important to determine as many general aspects of the project as possible by communicating with the client. It’s even more important than in our close-to-ideal scenario before. Why? Simply because we now should be focusing on the bigger parts of the project and we can assume that we will have to take care of the details. At this stage of the project, it might not be important, for example, how something will look like or how, let’s say, restoring a forgotten password would work. Based on information acquired from the client we can now prepare, you guessed it, user stories. The difference here is that we won’t be splitting those user stories into smaller tasks to estimate them individually, saving us some time.  And doing that shouldn’t be that hard - a whole lot of projects have some similarities between them, just like logging into an app in the example mentioned before. &lt;/p&gt;

&lt;p&gt;I have stated before (twice already and I can’t promise that I won’t do that in the future) that using other tools, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;creating a schema,&lt;/li&gt;
&lt;li&gt;BPMN diagrams, &lt;/li&gt;
&lt;li&gt;preparing mockups. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of above could help us to guide our project from the beginning and estimate the costs. I stand by it, but it is worth saying that using those is not essential. When the circumstances aren’t as we hope for them to be, we can skip them and go back to them at later stages. It will allow us to create a faster, but slightly less precise estimation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Thus, though we have heard of stupid haste in war, cleverness has never been seen associated with long delays.”&lt;/em&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%2F4j430dc2ug831wc61074.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4j430dc2ug831wc61074.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;According to TAoW a country never takes advantage of prolonged warfare. It can exhaust the country's resources to a minimum and bring many to a fringe of poverty. Maybe poverty itself is not a real issue in our case, but it definitely could influence the financial state of our company. That’s why we should prevent stagnation in our project - this includes preparing estimation. Sure, the first approach that I talked about in this article will prolong the process somehow, but the key is to try our hardest to make this swift. For example, an email exchange with our customer that was supposed to bring us more light on the project could take days, taking into account that it is not our and our customer's only seizure. I know from my experience that setting up a call or meeting with a customer in person might be way more efficient than sending a bunch of questions and waiting for a response from the other side. The key here is to come prepared, so before the said meeting ask yourself a bunch of questions about the specific parts of the project. For example, if the user of an app should be able to create an account in it, then those questions could look like: &lt;em&gt;“What data user is supposed to fill-in? All of that data is supposed to be editable or just only some fields?”&lt;/em&gt;. This will help us to stay on topic instead of conducting a meeting about every small piece or the subjects that are not that relevant (at the moment at least). Also, a lot of the previously unspoken issues can come up during such a short meeting so we could say that profit coming with them is double. If that’s not an option, then try to make your emails to be as precise as they can be and point out those aspects of a new project that need to be discussed more further. While asynchronous work is the approach to go with by default, it is worth realizing that there are some scenarios when actual talking live could be more fruitful. &lt;/p&gt;

&lt;p&gt;So, to conclude, how exactly should we choose “strategy to adapt and tactics to adjust to”? Well, it depends. Just like a commander of an army, in the face of a new challenge, we have set goals to accomplish while making sure that those goals are achievable. That’s why we need to be fully aware of the resources to our disposal and tailor our plans according to that knowledge. By following the same approach in every situation we expose ourselves to a risk of losing otherwise winnable battles and, in the long term, even a war.&lt;/p&gt;

&lt;p&gt;Keep in mind that's my interpretation of a second and third chapters of TAoW. I'm aware that many of you will have different thoughts about the subject and I'm really looking forward to read about them in the comments section! &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>leadership</category>
      <category>discuss</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Synchronous and Asynchronous JavaScript for Beginners</title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Tue, 24 Sep 2019 10:35:10 +0000</pubDate>
      <link>https://forem.com/2nit/synchronous-and-asynchronous-javascript-for-beginners-5f9p</link>
      <guid>https://forem.com/2nit/synchronous-and-asynchronous-javascript-for-beginners-5f9p</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was created by our dev Bartosz. It is also the next part of the bigger series, all the previous parts you can find &lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&gt;here&lt;/a&gt; :).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A lot of water in the river has passed since my last posts about &lt;a href="https://www.2n.pl/blog/es6-part-6" rel="noopener noreferrer"&gt;Javascript&lt;/a&gt;. It was not easy to find time for the next part. But ... I succeeded and would like to share something that has been bothering me for quite some time.&lt;/p&gt;

&lt;p&gt;If you read my posts, you might remember that I mentioned that javascript works synchronously and is a &lt;a href="https://www.2n.pl/blog/javascript-part-6" rel="noopener noreferrer"&gt;single-threaded language&lt;/a&gt;. And what about this asynchronicity? What about AJAX requests? What about fetching data from external APIs asynchronously? I decided to go over all of this and break it down to the smallest pieces to present it in a most approachable way. In a way that I would love to learn from. Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single-threaded Synchronous
&lt;/h2&gt;

&lt;p&gt;I know that I have already written about it but I would like everything to be at hand. I hope that after reading what I want to tell you, you will not feel the need to look elsewhere to find out about the basics of the synchronous and asynchronous facets of your Javascript.&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%2Fvwq29i5h7hd3qwva6hhn.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%2Fvwq29i5h7hd3qwva6hhn.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what about this single-threadedness and the synchronicity of Javascript? It all boils down to two very essential functionalities of the language. Namely, no matter how many lines our code has, everything we wrote will be done one line after another and one command at a time. Javascript has one thread in which the commands written by us are executed and the next one will be performed only when the previous one is completed. The end. Hey, but the asynchroninicity... - you might ask. I know, I know, but please wait a bit. Now it's time for my favorite console.logs.&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%2Fkmr9ewrk3lzm51lij7fj.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%2Fkmr9ewrk3lzm51lij7fj.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even in this case, when we do not perform complicated tasks, the command &lt;em&gt;console.log('World')&lt;/em&gt; will be executed only when the first one - &lt;em&gt;console.log ('Hello')&lt;/em&gt; is completed. One thread, synchronous. However, my most beloved example is below, which although when looking at it, it seems that it should return the true, it does not.&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%2Fe0nn30cevve61et3nrew.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%2Fe0nn30cevve61et3nrew.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is because the JavaScript engine does not look at this expression &lt;em&gt;(3 &amp;gt; 2 &amp;gt; 1)&lt;/em&gt; as a whole. Of course, in the first step, it estimates &lt;em&gt;3 &amp;gt; 2&lt;/em&gt; which returns &lt;em&gt;true&lt;/em&gt; thanks to basic math. This &lt;em&gt;true&lt;/em&gt; is parsed to the number of 1 because we do not know if a true is greater than the number of 1. In the end, the engine looks at the &lt;em&gt;1 &amp;gt; 1&lt;/em&gt; which is false therefore result of the whole expression is false.&lt;br&gt;
So once again in a nutshell - one thread, synchronous.&lt;/p&gt;

&lt;p&gt;After this thrilling introduction, which was really just a reminder, we are moving to ... another repetition of what I have already written in previous posts (&lt;a href="https://www.2n.pl/blog/javascript-part-5" rel="noopener noreferrer"&gt;Execution Context: Execution Phase&lt;/a&gt;, &lt;a href="https://www.2n.pl/blog/javascript-part-4" rel="noopener noreferrer"&gt;Hoisting, Execution Context: Creation Phase&lt;/a&gt;, &lt;a href="https://www.2n.pl/blog/javascript-part-7" rel="noopener noreferrer"&gt;Invocation, Execution Stack&lt;/a&gt;). Execution Context and Execution Stack (also known as Call Stack). The first one appears every time we invoke the function and has its information about for example variables. The latter is simply the stack on which the Execution Contexts of the called functions are pushed. In this case, however, no words depict it as well as a few lines of 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%2Fn7uvnwq9ty9heoocpt7p.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%2Fn7uvnwq9ty9heoocpt7p.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why so many console logs? Well, I think that nothing will present it better than just logging what happens at the moment. When we run the script, all variables and function statements will be stored in memory (&lt;a href="https://www.2n.pl/blog/javascript-part-4" rel="noopener noreferrer"&gt;hoisting&lt;/a&gt; ladies and gentlemen), and then the code will start to execute (Execution Phase). I will use chrome dev tools and put in a few breakpoints, thanks to which we will be able to pause the execution of the script at any time.&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%2F1xmx47biwuczwpkv3iq9.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%2F1xmx47biwuczwpkv3iq9.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I set them at the beginning and end of each function and the logs will inform us when the function code began to execute and when it ends.&lt;br&gt;
As the code is executed from top to bottom, nothing will happen until the line 23 ... and then boom, the first console.log appears.&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%2F0l3xu4io3twb8hlfqts2.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%2F0l3xu4io3twb8hlfqts2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Breakpoint set at the beginning of the function one (attention! Breakpoints pause BEFORE the marked line, in this case BEFORE console.log!) informed us that console.log('Im about to invoke one function!') and one(myNumber) was executed. On the other hand, console.log('I just finished everything!') did not show even though it is a line below. Why? Why does it look like if we were at the 4th line? Because the Execution Context of invoked function was pushed on the stack and everything after that does not matter to the JavaScript engine at the moment.&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%2Fbvp3i4bumo0btrtmh56q.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%2Fbvp3i4bumo0btrtmh56q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we have a blue arrow that shows us in which Execution Context currently executing code is. Ok, now let's get to the next breakpoint. Will it be in line 7?&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%2F40a22axsyd1nnw9cfkhf.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%2F40a22axsyd1nnw9cfkhf.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, it turns out that we are already in the function two and nothing that was after the invocation of this function has been called. So…&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%2Fv6w4a5fhwsydsfvii4pb.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%2Fv6w4a5fhwsydsfvii4pb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;... must wait. On the other hand, the Execution Context of function two lands on 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%2F01wkuiqun3vemol2bs7f.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%2F01wkuiqun3vemol2bs7f.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In it, the function three is called and everything works the same as in the first case. The last console.log has to wait because we have arrived in the Execution Context of function three.&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%2F05o15iwvvdr21lfdljcs.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%2F05o15iwvvdr21lfdljcs.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The matter here is simple. We do not invoke anything (in function three), so the whole thing is over now. In the console we have:&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%2Fpreeacnzkahclzpyt4az.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%2Fpreeacnzkahclzpyt4az.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, what about the rest of the code? Do we forget about it? Of course not. Since we will not create a new Execution Context at this stage, when everything is done in it, it will automatically be poped from our stack and... &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%2F7506dfo25u0o01mlzcny.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%2F7506dfo25u0o01mlzcny.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;... we will come back to …&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%2Fdctfrfpgtu1226j0w4hn.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%2Fdctfrfpgtu1226j0w4hn.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we are back in the Execution Context of function two, and it turns out that there is still something to do. The closing console.log is printed and as above, we pop the Execution Context from the stack. The last one remains.&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%2Ful2b9uw6rdt6t6b21fxa.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%2Ful2b9uw6rdt6t6b21fxa.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, everything that's left is getting done.&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%2Fzuca5daakzfsxbviqccl.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%2Fzuca5daakzfsxbviqccl.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And since everything has been done, the stack is empty! Phew, lots of pictures behind us so maybe now is the time for something that is not a repeat?!&lt;/p&gt;

&lt;p&gt;I mentioned above that I wanted everything to be in one post but there is one more reason why I decided to do this "small" reminder. Now imagine that when visiting various websites, the example discussed above is the only way the websites operate. Something must be done for the next thing to be started. You probably agree that it would be very burdensome from the user's perspective. A good example is something like that.&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%2Fhnci14c6d4hkd406nk1y.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%2Fhnci14c6d4hkd406nk1y.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The function waitFiveSeconds does what it's called - it waits five seconds. Because JavaScript is single-threaded and synchronous, it does not matter how many time we would click the mouse in the first 5 seconds. In the end, the result would be:&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%2Fvtwpyxo14gv2t2sw1epn.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%2Fvtwpyxo14gv2t2sw1epn.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Believe me, I tried very hard. As I wrote above - it would be very tedious. However, fortunately, JavaScript activity in the browser is more complex and what happens in the main and only JavaScript thread is not the only thing that actually takes place in the browser. It would be too boring right?&lt;/p&gt;

&lt;p&gt;However, what did the above example show us? Mainly that blocking what is supposed to happen in the main JavaScript thread is very dangerous. If something that takes some time to execute would land on the stack, it could easily break the user's experience of visiting our website. Since we already know that it should not be done, what can we do instead? The answer is simple - Asynchronous Callbacks.&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%2F0qa3c16opok6pxeu0cif.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%2F0qa3c16opok6pxeu0cif.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, we have two functions. One is invoked on click (onClick) and calls setTimeout(). setTimeout in our case accepts two parameters. The first is the function (also called a callback function) that we want to invoke. The second tells how long will it take to invoke the passed callback. This time, clicking on the browser window will result in this:&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%2Ffs3hwh9kq500r98c4hyp.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%2Ffs3hwh9kq500r98c4hyp.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, we have two functions. One is invoked on click (onClick), which implies setTimeout(). setTimeout in our case accepts two parameters. The first is the function (also called a callback function) that we want to invoke. The second tells how long will it take to invoke the passed callback. This time, clicking on the browser window will get something like that:&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%2Fq1s1e2dest4yboft69sn.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%2Fq1s1e2dest4yboft69sn.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I mentioned above, many things can happen in the browser, some of them being the event loop, the task queue, and web APIs. The latter, eg ajax requests, setTimeout or DOM (document itself) communicate with the stack and task queue. Let's take the last piece of code as an example. Some might have been surprised that the code seemed to go away without waiting for the waitFiveSeconds function. This is because setTimeout uses the timer API. The whole action is put away from the stack for the time equivalent of the number of ms we gave as the second parameter. Besides, setTimeout callbacks are asynchronous. Of course, not all callbacks in JavaScript act like that. Even more so, most of them are synchronous. For example callbacks that we pass to array methods like map() or filter(). However, some behave asynchronously. The simplest and most often used in examples is setTimeout. It lets us simulate fetching data from the server.&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%2Fjwgewbljyjqvx0df07ok.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%2Fjwgewbljyjqvx0df07ok.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As the function waitFiveSeconds was temporarily released from the stack, "I was clicked!" appeared in the console. After 5s, the function waitFiveSeconds will be pushed from the web APIs to the task 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%2F31icsilgkvlqi6b0rg3j.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%2F31icsilgkvlqi6b0rg3j.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Task queue is nothing more than a queue on which tasks are pushed. Nothing prevents you from queuing up more than one task. Of course, we do not want the asynchronous functions to be forgotten, so we have to somehow redirect them back to the stack. Fortunately, we do not have to solve it personally - if our stack is empty (meaning nothing is to be done, no execution context has been created) and our task queue is not empty, the first thing is pushed out of the task queue. As the function waitFiveSeconds was temporarily released from the stack, "I was clicked!" appeared in the console. After 5s, the function waitFiveSeconds will be pushed from the web APIs to the task 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%2Fmv6pkpwnkw3ara75dc39.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%2Fmv6pkpwnkw3ara75dc39.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The most common example of using setTimeout is when we set the second parameter to 0. After a slight change in the last code, what do you think will happen?&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%2Fhq49614e0ji0m4tm49dj.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%2Fhq49614e0ji0m4tm49dj.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Precisely, the result is very similar to the previous 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%2Fseeqpqcrrxph5dyaueh6.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%2Fseeqpqcrrxph5dyaueh6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is because function waitZeroSeconds has been postponed and will only be executed when our stack becomes empty. Considering that, after a click, our stack cannot be empty because the Execution Context of the function onClick lands on top of it. Only after everything that has been initialized in it is popped off the stack (in our case - console.log ('I was clicked')), the function waitZeroSeconds will be performed.&lt;/p&gt;

&lt;p&gt;Since we already know about things like JavaScript asynchronicity in the browser and how synchronous JavaScript deal with this, let's look at an example in which we have two simple queries to an external API, and two console.logs outside them.&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%2Feexouyqyadqzxzqcba8x.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%2Feexouyqyadqzxzqcba8x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fetch is a modern replacement for the XMLHttpRequest and takes place asynchronously. It is used to send requests to API to retrieve data.&lt;/p&gt;

&lt;p&gt;The matter is simple. At the beginning in the console we get:&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%2Fcrn2km4rwni87aun911x.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%2Fcrn2km4rwni87aun911x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since we know that fetch works asynchronously, we'll get a console.logs after the stack is cleared. The question is, however, in what order? (hint: check the number that indicates the amount of data fetched).&lt;/p&gt;

&lt;p&gt;So? &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%2Fuca671ntvhw9ycksnr3y.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%2Fuca671ntvhw9ycksnr3y.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everything nice and easy, right? Almost. In the example above, a thought arises - what if we would like to get the data first and use it in the second query? Let's take a look at another case.&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%2F6x0xoq0ih0nzqp58g01v.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%2F6x0xoq0ih0nzqp58g01v.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that we do not know the id of the post and send the request to endpoint ... / posts / 1 to actually get it. Then we want to use the saved id and retrieve all comments belonging to this id.&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%2F38j5cjkkef6ld3e28q4z.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%2F38j5cjkkef6ld3e28q4z.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately, we did not succeed. This is due to the fact that what landed on our stack was a query without information about the id. Now we will modify the above code a bit.&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%2Fldgwr72k0t45hotttv3v.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%2Fldgwr72k0t45hotttv3v.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consolidating knowledge is the basis, so I describe the order once again.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;before getComments&lt;/li&gt;
&lt;li&gt;inside getId&lt;/li&gt;
&lt;li&gt;id in getComments function&lt;/li&gt;
&lt;li&gt;after getComments&lt;/li&gt;
&lt;li&gt;all comments&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What can we do to properly get data about comments? There are few solutions but the newest / most popular is using async / await.&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%2Fxhjg2rqho8nihwfp3h7i.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%2Fxhjg2rqho8nihwfp3h7i.png"&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%2Flxh9o6p2r5h9jhotb9w5.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%2Flxh9o6p2r5h9jhotb9w5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simple and pleasant right? The only thing we did was add two keywords - async / await. However, what really happened? Here we will have to enter the territory called Promise in Javascript.&lt;br&gt;
What are the Promises? First of all, these are objects, and secondly, they are quite specific objects.&lt;br&gt;
Most importantly, they are simply promises that occur in a similar form as in everyday life. Each of us has promised something at some point of our lives. To the parents, that we will clean the room, the employer, that we will be on time in the office. Every promise has two stages. The first stage is the stage that I like to call transient. It looks like we made a promise that we'll take out the trash before the end of the day. Since we still have time, our promise is in the 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%2Fh29ngcnxtx44s9bkuivw.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%2Fh29ngcnxtx44s9bkuivw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;that is waiting for the final result. In this case, the value will be undefined. The next stage will tell us whether we were able to take out this unfortunate trash before the end of the day or not. If yes and our mission has been successful, then the status will be easy to guess -.&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%2F2vrzlj45a8l662qp8w77.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%2F2vrzlj45a8l662qp8w77.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, for example, the value is simply an empty string. If, however, we have forgotten and we have failed to fulfill the promise, then the status will be (also an empty string used).&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%2Ffzb4pwm07buam2lac4wg.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%2Ffzb4pwm07buam2lac4wg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Depending on the status, different things can happen. Let's start with a simple 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%2F7wraunpinwa91p1mrjge.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%2F7wraunpinwa91p1mrjge.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"What the hell is going on here" - you might ask? Well, through new Promise, we create a new object that accepts the callback function with two parameters - resolve and reject, which we later use depending on whether we are above or below 18 years. As you can easily guess, the resolve will serve us to handle the variant when we fulfill the promise and reject when we do not fulfill this promise. It seems pretty simple, right? Now let's move on. If you promise something then ... Well, then what? Here the keyword "then ()" sneaks in. Promises that are fulfilled will be a resolved promise object. "then ()" takes this value and uses a callback function to process it in some way. Let's modify the code a bit and then use then ().&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%2Fp1khbguerbmbowvy933v.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%2Fp1khbguerbmbowvy933v.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look. In then() we used a callback with the msg parameter. Because we already know that the promise will be fulfilled, msg will accept the value of the argument we have in resolve (). In our case, it will be a string - "I am old enough to ...". Thanks to that we will get&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%2Fmwsork1v2nbl1disomqe.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%2Fmwsork1v2nbl1disomqe.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's see what happens when we change the age in a variable to less than 18, let's say 17.&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%2F5kx737vo8qgb7c1xhtoi.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%2F5kx737vo8qgb7c1xhtoi.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We got a mistake. This is because then() is used to handle your resolved promises. If, on the other hand, we want to catch a promise that we have not been able to fulfill (was rejected), we will use catch(). So let's add catch() to the code and keep the age of 17.&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%2Fiaavrlxc0toc2qi4rr6a.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%2Fiaavrlxc0toc2qi4rr6a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will look like this. Of course, the principle is the same. In the error parameter, we get an argument but this time with reject() string "What a shame". Yes, the result will be: &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%2Fv7hvi1croieerggcby7c.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%2Fv7hvi1croieerggcby7c.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I suggested. Everything is fairly simple and transparent. Ok, let's add one promise..&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%2Fiqx22ry8lhpl98eha5cr.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%2Fiqx22ry8lhpl98eha5cr.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we have created the order function that will return us a Promise. It's the same Promise as the previous one, the only difference is that it's always resolved in this case, so its value is an argument in resolve(). But what more interesting is what is at the bottom. In the 17th line, we called the function order. Thanks to the fact that in then() we return Promise, we can use again then() (at the end we return the promise), but this time the result of fulfilling the promise will be the argument given in resolve (), which is in the function order.&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%2Fs5e21s08lylzhwzey2k7.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%2Fs5e21s08lylzhwzey2k7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what about all of this? What does this give us? Well, thanks to this, we can chain Promises and pass the results from previous Promises to the next ones. Also, the result will always be passed (resolved or rejected Promises) which is very helpful in communicating with external APIs. I will modify the previous code a bit, add some functions that return Promises and chain them.&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%2Fs1t95wtudxkb333xf3vc.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%2Fs1t95wtudxkb333xf3vc.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By capturing values ​​in the parameters of callback functions, we can pass everything down the line. Let me also mention that it is worth remembering that we should always use catch() to be sure when something unexpectedly fails. Thanks to using Promises we do not have to call catch() for each function then(). It's enough to add 1 catch() at the end of any chain of Promises.&lt;br&gt;
Ok, after this brief description of Promises, let's go back to async / await thanks to which we were able to firstly get the post's id and then use it to fetch further information from the API. So what does async / await do? Let's go back to the previous 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%2F6fxu14a3rgb9xv9njp0o.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%2F6fxu14a3rgb9xv9njp0o.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why did it work? We have received the desired result because await stops the execution of the further part of the function until the moment we get the response. For this reason, only when the function getId is able to return the id, console.log from line 11 and everything that is in the function will be completed. This is a very important thing. We should only use it when we know that action would block the main javascript thread, which would prevent the user from interacting with the application. Okay, but what else does it give us? Well, async / await introduces several facilities that make the code more readable.&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%2F18fsz6fv48mkmzhcu4ot.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%2F18fsz6fv48mkmzhcu4ot.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we have an earlier code with some changes. We removed all then() and the code looks somehow nicer, right? Using await, we not only stopped further execution of the function's code but also obtained immediate access to the answer that Promise returns from fetch.&lt;/p&gt;

&lt;p&gt;As you can see, I did as I promised. I tried to include all relevant information in one post. Of course, you could add a bit more to it but in the end, I think that if someone as a novice developer would like to learn more about how the asynchrony works in Javascript, then he has almost all of the needed information here.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Art of Project Management - part 1</title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Mon, 09 Sep 2019 09:44:42 +0000</pubDate>
      <link>https://forem.com/2nit/the-art-of-project-management-4ed2</link>
      <guid>https://forem.com/2nit/the-art-of-project-management-4ed2</guid>
      <description>&lt;h2&gt;
  
  
  INTRODUCTION
&lt;/h2&gt;

&lt;p&gt;“The Art of War” by Sun Tzu is already well-known East Asian ancient warfare guide. It contains complex advice on how to approach an upcoming war, how to conduct the reconnaissance of the enemy, how to turn the enemy's weaknesses into our advantage, how to manage the army and, generally, how to succeed with massive military operations. &lt;em&gt;“Ooook, but what all of this has to do with Project Management?”&lt;/em&gt; - you might ask. Well, a lot. Project Manager, just like the Commander of an army, should be able to properly set the initial concept, choose adjusted strategy and tactics, estimate available resources, manage those resources wisely, attain previously set objectives, gather information and recognize the risk bound to the planned procedures. For some of you, It may sound easy, but for sure it can be tricky - it gets a lot harder with a big scale project, simply because those require a lot more attention. But the bits of advice given in TAoW is as useful even when the project that you’re leading isn’t that big.&lt;/p&gt;

&lt;p&gt;This article is my interpretation of TAoW related to comparison of conducting a war to efficient Project Management for a web or mobile app. I’m pretty sure that your opinions and reception of TAoW may be a lot different, that’s why I'm inviting you to discuss this subject in the comment section.&lt;/p&gt;

&lt;p&gt;So, let’s jump to the first chapter!&lt;/p&gt;

&lt;h2&gt;
  
  
  Initial Estimations - Project Concept
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;“Now the general who wins a battle makes many calculations in his temple where the battle is fought. The general who loses a battle makes but few calculations beforehand. Thus do many calculations lead to victory and few calculations to defeat: how much more no calculation at all! It is by attention to this point that I can foresee who is likely to win or lose.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;According to TAoW, preparations for war are the best way to enter the conflict without chaos, randomness or insecurity. Many different factors are crucial in each battle and could overwhelm the scales of victory. For every commander it’s very important to be aware of those factors beforehand - after the war has started it is probably already too late to investigate them. We can see an obvious parallel to Managing Projects right there. When we know that there is a possibility of “war” (in our case - a new project) on the horizon, we should be prepared and we should be familiar with all of those factors, that could make an impact on our project in one way or another. But how could we define them? According to TAoW, five elements are important while pursuing a success: the Moral Law, Heaven, Earth, The Commander, Method and Discipline that might be useful. Let’s talk about each of them some more.&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%2F0b89bnpg0g8w32x5114c.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%2F0b89bnpg0g8w32x5114c.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Moral Law factor is responsible for willingness, that subordinates manifest about following their ruler. On the Moral Law depends, whether those subordinates will follow him undismayed. For this, the ruler has to earn their trust by showing that he is competent, reliable and, of course, trustworthy. Accomplishing complete accord between ruled (your team members) and their ruler (you, as PM) is always a great starting point to perform any complex maneuvers. The best way to accomplish that is to, simply, practice. When we and our team are put in the state of standby, we must have full clarity as to what actions should be taken, in what order and it’s nearly impossible without prior training. But how to train without having a new project already? Well, there are some possibilities. In our company, we started our project for learning purposes (assuming, however, that this project may bring more tangible benefits in the future, both for us and for others). It was a project of a web app, responsible for the efficient management of the football (soccer if you’re American ;) ) pitches in our city. The goal was making those pitches more available for residents and making the whole process of booking of sports facilities more organized. We approached this project just like we would approach any “real” project. We’ve designed basic functionalities, we prepared mockups for most of them, created documentation and we started to work on them. It was a bit challenging to coordinate because there was no permanent team of developers working on the project - those who had some spare time jumped in and those who were given new tasks in "real" projects were moving away from it. But we gained some experience and learned how to effectively organize ourselves - our practice exercise paid off.&lt;/p&gt;

&lt;p&gt;Heaven described by Sun Tzu means the cycle of night and day, times, seasons and weather - all of the surroundings considerations. In our case seasons may respond to things like summertime, when a lot of people want to go on holidays - the time when developing a project could slow down. The same could be true in a winter holiday season, especially considering Christmas and New Year’s Eve (or different holidays, depending on the region). All of this could influence our estimations in a major way, so it is important to keep this in mind. The other crucial factor connected to Sun Tzu’s Heaven is the cycle of night and day. Your team members don’t have to necessarily work in the same place, they could be spread out all around the world. That’s why you must be prepared to coordinate their work while having in mind different time zones, which might not be an easy task. Those considerations won’t always be the same to you as a PM of course, but the ability to know your surroundings, limitations and making certain predictions about what is going to happen is extremely important.&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%2F3wdb4o6rq9hwr0c8v0dk.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%2F3wdb4o6rq9hwr0c8v0dk.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Earth mentioned in the first chapter of TAoW refers to distances, different terrains that might decide on success or defeat. As PM’s we, thankfully, don’t have to study topography, but we have to realize what kind of technology should be used in our project and what are the benefits and risks resulting from it. Just like good commander should predict how marching through narrow passes, steep hills or moldy swamps will impact mobility and safety of his army, you should predict how chosen technology - designated “path” - will impact maintaining the project or its expansion.&lt;/p&gt;

&lt;p&gt;The Commander factor stands for all of the characteristics of a leader, that makes easy for subordinates to entrust management - his wisdom, honesty, strictness. When a Commander can display them, it shouldn’t be hard to believe that he is capable of leading others to success. It's worth noticing that wisdom and sincerity are considered more important than other Chinese cardinal virtues while courage and strictness are replacing uprightness of mind and self-respect, self-control. This means that, as the PM's, we should place particular emphasis on the correct interpretation of the information available to us, a reliable assessment of the current state of affairs, integrity and, at the same time, a certain and firm approach to the circumstances encountered, whether favorable or not.&lt;/p&gt;

&lt;p&gt;Method and discipline refer to proper management of the available human resources, hierarchy and structure, provision of tools and adequate environment. It’s pretty simple really - just like in managing army, you have to manage your team working on project: determine the chain of command and responsibilities assigned to each member while providing everything that will be needed for your team members to be able to solely focus on their goals without any distractions - within reason that’s it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“The art of war, then, is governed by five constant factors, to be taken into account in one’s deliberations, when seeking to determine the  conditions obtaining in the field.”&lt;/em&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%2Fbv1rk1ipyfvemlcs3a6h.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%2Fbv1rk1ipyfvemlcs3a6h.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Those five factors are the pillars of good preparation, but keep in mind that it is possible to gather more information before the beginning of the huge operation than covered in those factors. This information or occurrence of other circumstances should result in adjusting our approach to operation accordingly, even independently of adopted rules.&lt;/p&gt;

&lt;p&gt;Ok, so  - thanks to TAoW - we established that it’s crucial to identify those important pillars and adjust our planning to relying on this identification. This seems easier to say than do. But no worries - there are many, many tools that could be valuable in the process of identifying some of the pillars mentioned above. One of them is creating BPMN diagrams, depicting the processes that will take place in your app and the whole logic beneath. You can think of them as strategic maps, helpful while planning the next move of your army. Those diagrams (or maps) are supposed to help you with setting directions, plan resource management and shell out possible difficulties that may occur on the way of your subordinates to a set goal. You can also pair your BPMN diagrams with mockups of the app, or even use tools like GraphQL Editor (I wrote one post about it some time ago, you can read it &lt;a href="https://www.2n.pl/blog/managing-projects-with-graphql-editor" rel="noopener noreferrer"&gt;here&lt;/a&gt; - it's even related to the training project in our company that I mentioned before). With the combined force of those, you can achieve a level of transparency in your project between you, your team members and your client that would be extremely hard to accomplish without those tools. One of your team members isn’t sure how something should work? Ok, here’s a diagram that explains it. Your customer has a hard time to figure out how something should look? Ok, no problem - there's a mockup for it, that we agreed upon earlier. Building diagrams and mockups will help you to predict potential difficulties, the impact of the chosen technology. They will help you choose the right “path” for your 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%2Fba90ya4dl4jd5ufhl9n3.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%2Fba90ya4dl4jd5ufhl9n3.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is pretty simple to compose flow and look of your app using tools like that, and using them could eliminate a lot of major or minor issues that could occur otherwise. This approach will save you a lot of potential stress in the next stages of the project implementation as well. So in this case, with small contribute comes a huge profit. And I mean HUGE.&lt;/p&gt;

&lt;p&gt;So, we already talked about defining the five pillars of preparation leading to success and the way to translate those pillars mentioned in a book for our real-life projects. Is there anything more that we could extract from the first chapter of TAoW that could help us be a little more self-aware while starting a new project? I would say “yes”, and that's why: the following parts of TAoW’s first chapter advice identification of the enemy’s weak spots and exploiting them. While we, PMs, are approaching a new project there is no literal “enemy”. But still, we could gain a lot from that advice. Just think about all of the unforeseen circumstances, unexpected problems, lack of funding, lack of time and every other negative aspect of developing a new project that could sneak in, and try to perceive all of this as one - this is our true enemy. He is built from those factors. Our job is to investigate those and fix them (or even better - prevent them from happening), instead of exploiting. Defeating this enemy by good management will allow you to create a state when your team members will be 100% sure what they are doing and why they are doing it. Believe me, once you experience that state you will never want to go back.&lt;/p&gt;

&lt;p&gt;This is the first article of the series. I hope that at least some of you will enjoy it, and some of you will express your opinion on it in the comment section :). Thanks!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>leadership</category>
      <category>discuss</category>
      <category>productivity</category>
    </item>
    <item>
      <title>ES6 for beginners - Part 6 (Destructuring, Template Strings) </title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Fri, 14 Jun 2019 11:23:44 +0000</pubDate>
      <link>https://forem.com/2nit/es6-for-beginners-part-6-destructuring-template-strings-2cbc</link>
      <guid>https://forem.com/2nit/es6-for-beginners-part-6-destructuring-template-strings-2cbc</guid>
      <description>&lt;p&gt;&lt;em&gt;This is the sixth part of ES6 tutorial, created by our dev Bartosz. All of the previous parts you can find &lt;a href="https://www.2n.pl/blog"&gt;here&lt;/a&gt; :).&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  destructuring
&lt;/h2&gt;

&lt;p&gt;In the current post, we will start with the code using ES5 syntax.&lt;/p&gt;

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

&lt;p&gt;Imagine we have a simple code like that somewhere in the project.&lt;br&gt;
Now comes the time that later in our code we want to refer to our object and extract some data from it. We would probably do it this way. A simple dot notation allows us to get data from the object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4jJXeRog--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dxn956yr16hmfqy6b4b7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4jJXeRog--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dxn956yr16hmfqy6b4b7.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is this a good way? Of course. Could we do better? Since the ES6, there is a way. You've probably heard about DRY a lot, which means Don't Repeat Yourself. In the example above, as you can see it yourself, we repeat ourselves several times. Two &lt;strong&gt;vars&lt;/strong&gt;, two &lt;strong&gt;expenses&lt;/strong&gt;, two &lt;strong&gt;types&lt;/strong&gt;, two &lt;strong&gt;amounts&lt;/strong&gt;. This is a place where ES6 comes handy to let us simplify writing a bit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GaN1Wj-3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/h2ht1dvcpihwtbnlo0ey.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GaN1Wj-3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/h2ht1dvcpihwtbnlo0ey.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What we wrote with ES6 is completely equal to what we used before. This way of writing means that from the expanse object, we want to extract &lt;strong&gt;type&lt;/strong&gt; and &lt;strong&gt;amount&lt;/strong&gt; then assign them to &lt;strong&gt;const&lt;/strong&gt; variables with the same name. We must remember that we need to specify exactly what we want to refer to by using the same variable name.&lt;br&gt;
But aren't there still any duplicates in the example above? Of course, there are. So let's modify our code even more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KOWuRXKm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6hzsbtp9kceef7zf5ebj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KOWuRXKm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6hzsbtp9kceef7zf5ebj.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we completely got rid of the duplicates. Let's check the console if everything works as it should.&lt;/p&gt;

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

&lt;p&gt;Cool. If it works now, will it work if we change the name of the variable to another one that does not exist in the object?&lt;/p&gt;

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

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

&lt;p&gt;Unfortunately, but no. The convention of this says clearly that the variable name has to be the same as it is in the object. But what if we really really what to use a different name of the variable? Well, there is also a solution for that but try to solve it yourself (a small hint, use a colon and the name of the new variable).&lt;/p&gt;

&lt;p&gt;What else can we do using &lt;strong&gt;destructuring&lt;/strong&gt;? For example, we can extract a parameter passed to a function. We will start as above from the script written using ES5.&lt;/p&gt;

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

&lt;p&gt;Ok, hold on. And what is this notation ?! Here we are dealing with another feature from ES6, &lt;strong&gt;template strings&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  template strings
&lt;/h2&gt;

&lt;p&gt;For a moment we will leave &lt;strong&gt;destructuring&lt;/strong&gt; to see what template strings are.&lt;br&gt;
&lt;strong&gt;Template strings&lt;/strong&gt;, or otherwise &lt;strong&gt;template literals&lt;/strong&gt;, are nothing more than syntactic sugar in JavaScript. Here, we will also use two examples. The first one will be something you probably used to do using JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--78oGSo6z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ftk1e298tmucpnhkaeht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--78oGSo6z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ftk1e298tmucpnhkaeht.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mq5L-Gwp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/a9hktfx406uov0z28pm5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mq5L-Gwp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/a9hktfx406uov0z28pm5.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We've all expected this. Once again, however, the question arises whether you can write it a little more elegantly. And the answer is once again that you can.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--czvzxk0l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/64xuedr6jd45p8hi355n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--czvzxk0l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/64xuedr6jd45p8hi355n.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Everything works correctly. Additionally, we do not have to limit ourselves to the &lt;strong&gt;year&lt;/strong&gt; variable. We can put any expression in &lt;strong&gt;{ }&lt;/strong&gt;. If we would like to receive a previous year, just change it to &lt;strong&gt;{year - 1}&lt;/strong&gt;, etc. It is possible that it is not visible enough but we use backticks to write the template string. We can find them on the keyboard next to the number &lt;strong&gt;1&lt;/strong&gt; (on the left). And that's all you need to know. It is not complicated, and I think that it will often help with the code readability.&lt;/p&gt;

&lt;h2&gt;
  
  
  destructuring
&lt;/h2&gt;

&lt;p&gt;We are going back to the previous example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sAYsOuix--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3733kyk3l6u7tjrv37cf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sAYsOuix--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3733kyk3l6u7tjrv37cf.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we know what the &lt;strong&gt;template strings&lt;/strong&gt; are, we can go further. And what are we doing next? Of course, we try to use &lt;strong&gt;destructuring&lt;/strong&gt; to make our code more beautiful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JSaZseCN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6mvlramtblfv0vuwi23j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JSaZseCN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6mvlramtblfv0vuwi23j.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pvNscg-y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ueblllaki4rsq4xlgajg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pvNscg-y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ueblllaki4rsq4xlgajg.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once again everything works correctly. Instead of writing the name of the object every time we want to refer to one of its property. All you need to do is invoke the function with an argument, which will be the object. In the function, we will pass the properties to which we want to refer in the body.&lt;br&gt;
Everything is beautiful and nice but shortening the code is not the only thing for which &lt;strong&gt;destructuring&lt;/strong&gt; is used. Often &lt;strong&gt;destructuring&lt;/strong&gt; of an array is also used. When we were &lt;strong&gt;destructuring&lt;/strong&gt; objects, we were pulling off properties. &lt;strong&gt;Destructuring arrays&lt;/strong&gt; is about pulling off individual elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--35-1kKC9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dpi25lpbwk6te57tt26j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--35-1kKC9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dpi25lpbwk6te57tt26j.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Here is another way to use &lt;strong&gt;destructuring&lt;/strong&gt;. The difference between &lt;strong&gt;destructuring&lt;/strong&gt; of an array and an object is that &lt;strong&gt;{ }&lt;/strong&gt; has been replaced by &lt;strong&gt;[ ]&lt;/strong&gt;. I am encouraging everyone to play around with it a bit now. After that, we will take a look at the &lt;strong&gt;destructuring&lt;/strong&gt; the mix of arrays and objects.&lt;/p&gt;

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

&lt;p&gt;In the example above, we have an array with 3 objects. We know that using &lt;strong&gt;destructuring&lt;/strong&gt; we can extract data from both, first and second. Now let's see how it is done.&lt;br&gt;
Of course, we start with the array, as it is "outside" our objects. &lt;strong&gt;firstElementOfArray&lt;/strong&gt; will be our first object and in the first console.log. Of course, we will get the whole object back. If we add to this &lt;strong&gt;{ }&lt;/strong&gt; and change the name &lt;strong&gt;firstElementOfArray&lt;/strong&gt; to the name of the one object's property, in our case &lt;strong&gt;name&lt;/strong&gt;, we will get its value. Simple right? If we would like to gain access to the name but the other company, we would do it in the following way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5HAWwM6A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/k6uqmzku8olhig3d0sgj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5HAWwM6A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/k6uqmzku8olhig3d0sgj.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;It probably looks a little more confusing, but it is not that complicated. Let's start from the beginning. In the beginning, as the object is "outside", we start with &lt;strong&gt;{ }&lt;/strong&gt;. Now, to get to the location property, we have to type the variable exactly with the same name, i.e. location &lt;strong&gt;{ location }&lt;/strong&gt;. Leaving it this way, we would get all the values, i.e. &lt;strong&gt;["USA", "Poland", "Germany"]&lt;/strong&gt;. However, when our goal is to obtain only &lt;strong&gt;"USA"&lt;/strong&gt; we must use &lt;strong&gt;destructuring&lt;/strong&gt; once again, &lt;strong&gt;{ locations: [ locationOne ] }&lt;/strong&gt;. This way, we'll gain access to the first location of Google. Here I also encourage you to play ... rest.&lt;/p&gt;

&lt;p&gt;Thank you all for reading :). In the nex post, I'll be talking about &lt;strong&gt;asynchronous javascript&lt;/strong&gt;. All your feedback will be appreciated :). &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>ES6 for beginners - Part 5 (Array Helper Methods)</title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Fri, 07 Jun 2019 14:56:13 +0000</pubDate>
      <link>https://forem.com/2nit/es6-for-beginners-part-5-array-helper-methods-2103</link>
      <guid>https://forem.com/2nit/es6-for-beginners-part-5-array-helper-methods-2103</guid>
      <description>&lt;p&gt;&lt;em&gt;This is the fifth part of ES6 tutorial, created by our dev Bartosz. All of the previous parts you can find &lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&gt;here&lt;/a&gt; :).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the past, we had to have access to external libraries to use most of these methods. They were very popular and therefore it was decided to enter the ES6 standards.&lt;br&gt;
Now we have 7 &lt;strong&gt;Array Helper Methods&lt;/strong&gt; available.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;forEach&lt;/li&gt;
&lt;li&gt;maps&lt;/li&gt;
&lt;li&gt;filter&lt;/li&gt;
&lt;li&gt;find&lt;/li&gt;
&lt;li&gt;every&lt;/li&gt;
&lt;li&gt;some&lt;/li&gt;
&lt;li&gt;reduce&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By understanding what each of them does you're going to find that you can work with data collection more easily and the vast majority of web application out there is, you guessed it right working with a collection of data. But before we start, I want to mention quite an important thing. All these methods are themed around avoiding working with a manual for a loop. The entire goal of these methods is to stay away from the for loops. Ok, enough talking, it's time for the first one, &lt;strong&gt;forEach&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  forEach
&lt;/h2&gt;

&lt;p&gt;As this is the first method, I will spend the most time with it. Considering that all methods work in a very similar way, the next ones will be discussed for a shorter time.&lt;/p&gt;

&lt;p&gt;Let's start with the fact that for the last time we will write an ordinary and simple &lt;strong&gt;for loop&lt;/strong&gt;, which will console all array values.&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%2Feiqjmylga10if1io67v0.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%2Feiqjmylga10if1io67v0.png"&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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F95%2Fcontent_es6-1.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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F95%2Fcontent_es6-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, we got all the colors that are in the array.&lt;br&gt;
Then, let's do the same, only using the news from ES6, &lt;strong&gt;forEach&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%2Fae2zt25pl06f9ykuiaky.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%2Fae2zt25pl06f9ykuiaky.png"&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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F96%2Fcontent_es6-2.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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F96%2Fcontent_es6-2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, we received the same. This is half of the success. The other half is to understand what is really happening here, and it is not complicated.&lt;br&gt;
The &lt;strong&gt;forEach&lt;/strong&gt; method, which is called on an array, takes the parameter, which is the &lt;strong&gt;Iterator Function&lt;/strong&gt;. The function is invoked each time when the code in the function's body is executed. Then, our &lt;strong&gt;Iterator Function&lt;/strong&gt; also accepts one parameter, in our case &lt;strong&gt;color&lt;/strong&gt;, which will have an equal value starting from the first, up to the last value from the array. By convention, this parameter should have a singular form of the name of our array.&lt;br&gt;
Additionally, to run the code, we can create the &lt;strong&gt;Iterator Function&lt;/strong&gt; elsewhere lexically at the same level and simply pass it to the &lt;strong&gt;forEach&lt;/strong&gt; method. It would look like this way.&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%2Fu0pe174x39vyxsfrxd80.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%2Fu0pe174x39vyxsfrxd80.png"&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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F97%2Fcontent_es6-3.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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F97%2Fcontent_es6-3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we've passed both function statement, function expression, and arrow function.&lt;/p&gt;

&lt;p&gt;The main thing you need to remember while using &lt;strong&gt;forEach&lt;/strong&gt; method is that it mutates the array we are iterating over.  What if we would like to add string "color" after each of the array's item in our case? Then we would do it by simply concatenating every variable which holds value of the color with the "color" string. Since we are not returning anything but only modify already existing array there is no need for a return statement in the &lt;strong&gt;forEach&lt;/strong&gt; method.&lt;/p&gt;

&lt;h2&gt;
  
  
  maps
&lt;/h2&gt;

&lt;p&gt;How is this method different from forEach ? Mainly that after we do it we will get a new array.&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%2Fgb5tyrmeurqa2cz29ohh.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%2Fgb5tyrmeurqa2cz29ohh.png"&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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F98%2Fcontent_es6-4.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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F98%2Fcontent_es6-4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, I wanted to demonstrate two things at the same time. First of all, as you can see the way we use the &lt;strong&gt;map&lt;/strong&gt; method is identical to the &lt;strong&gt;forEach&lt;/strong&gt; method. Secondly, and it is more important, so I repeat, using the &lt;strong&gt;map&lt;/strong&gt; method, we create a completely new array. This function is used really often when we want to keep the old version of an array. For example, if the array has some numbers and in one place we would want them to be divided by 2 and in second place we would want them to be divided by 3. By using map method we keep the old version of the array. And since we are creating new array we need to include return statement in the map method.&lt;/p&gt;

&lt;h2&gt;
  
  
  filter
&lt;/h2&gt;

&lt;p&gt;Another method for iterating over the array. However, it is used in a strictly defined case. Let us assume that we have an array full of objects. As in the example below. Thanks to this method, we will be able to filter the results of our iteration. The main thing to remember using filter method is that it needs return statement and only conditions that are fulfilled are returned.&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%2Fthijr7utramrc2ce1651.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%2Fthijr7utramrc2ce1651.png"&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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F99%2Fcontent_es6-5.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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F99%2Fcontent_es6-5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we quickly and efficiently obtained data on the topic that interested us. We do not need to even use the if statements when using the &lt;strong&gt;filter&lt;/strong&gt; method. In addition, we do not have to limit ourselves to one condition. If we want to add a condition that the name equals "&lt;strong&gt;Tom&lt;/strong&gt;" we will do it in this way.&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%2Fs1a6axir8xr2tmjbpjxv.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%2Fs1a6axir8xr2tmjbpjxv.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  find
&lt;/h2&gt;

&lt;p&gt;The purpose of &lt;strong&gt;find&lt;/strong&gt; helper method is to look through an array. As soon as that element is found with given criteria in the array, a helper will return that record. It is really useful in a situation where we have a massive database with for example unique ids. Since ids are unique and iterating over just a part of the database is faster than everything we could use find a method to force iterating to stop when conditions are met (we found an id).&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%2F9d8hymk6flyqo21v21l8.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%2F9d8hymk6flyqo21v21l8.png"&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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F100%2Fcontent_es6-6.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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F100%2Fcontent_es6-6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We changed a bit the array from the previous example and replaced &lt;strong&gt;Greg&lt;/strong&gt; with another &lt;strong&gt;Mark&lt;/strong&gt;. As you can see here, the way of using the method is identical. The only thing to keep in mind when using the &lt;strong&gt;find&lt;/strong&gt; method is that when the JavaScript engine hits the first value that returns true, it will stop iterating further. So the second &lt;strong&gt;Mark&lt;/strong&gt;, which is at the very end, will not be included in the returned value. Also, the entire object was returned, not as in the &lt;strong&gt;filter&lt;/strong&gt; method which was an array.&lt;/p&gt;

&lt;h2&gt;
  
  
  every / some
&lt;/h2&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%2F2uxyuai6lr4yjkvk491e.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%2F2uxyuai6lr4yjkvk491e.png"&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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F101%2Fcontent_es6-7.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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F101%2Fcontent_es6-7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the value returned by every and some methods is boolean. For every method, the value will be true if everything matches the condition. When it comes to the &lt;strong&gt;some&lt;/strong&gt; method, it is enough that one value will be matched with the condition. As you probably already figured it out, we use it to check if the conditions we check will return true.&lt;/p&gt;

&lt;h2&gt;
  
  
  reduce
&lt;/h2&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%2Fk3jqh6tetab4waysdrmj.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%2Fk3jqh6tetab4waysdrmj.png"&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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F102%2Fcontent_es6-8.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%2Fwww.2n.pl%2Fckeditor_assets%2Fpictures%2F102%2Fcontent_es6-8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best way to explain reduce is an example of adding values ​​to an array. The &lt;strong&gt;reduce&lt;/strong&gt; method takes two parameters. The first is the &lt;strong&gt;Iterator Function&lt;/strong&gt; as in the previous examples. The second is the initial value that we can set. As you can see in the above example, we set the initial value to &lt;strong&gt;100&lt;/strong&gt; and added all elements to it.&lt;/p&gt;

&lt;p&gt;Finally, I would like to say one more thing. It was not hard to see that the old syntax was used to create functions. Here, I encourage everyone to try and replace everything so that everything works according to ES6 standards.&lt;/p&gt;

&lt;p&gt;In the next post, we will find out what destructuring is so stay tuned. :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>ES6 for beginners - Part 4 (Rest, Spread) </title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Wed, 05 Jun 2019 13:17:32 +0000</pubDate>
      <link>https://forem.com/2nit/es6-for-beginners-part-4-rest-spread-10p9</link>
      <guid>https://forem.com/2nit/es6-for-beginners-part-4-rest-spread-10p9</guid>
      <description>&lt;p&gt;&lt;em&gt;This is the fourth part of ES6 tutorial, created by our dev Bartosz. All of the previous parts you can find &lt;a href="https://www.2n.pl/blog"&gt;here&lt;/a&gt; :).&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  REST
&lt;/h2&gt;

&lt;p&gt;What is &lt;strong&gt;rest&lt;/strong&gt; in ES6? The rest parameter syntax allows us to represent an indefinite number of arguments.&lt;br&gt;
We know that in JavaScript functions can have any number of parameters. Besides, we do not have to give everyone an argument. This was mentioned in &lt;a href="https://www.2n.pl/blog/javascript-part-17"&gt;JavaScript Part 17&lt;/a&gt;.&lt;br&gt;
Now let's say that we have a function that takes an unknown number of parameters for us. Example of simple addition of several arguments by the user when we do not know about its number. Using the standard before ES6, we could do it in the following way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8XZs9cgT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vzv7d0dx0oe7el1uhzci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8XZs9cgT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vzv7d0dx0oe7el1uhzci.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the arguments are not stored in the array but in array-like format, we had to create a new array consisting of arguments. ES6 makes it easy for us to do the job using the &lt;strong&gt;rest&lt;/strong&gt; parameter.&lt;/p&gt;

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

&lt;p&gt;Using the &lt;strong&gt;myAdd function&lt;/strong&gt;, we can add an unlimited number of arguments. The reason for this is that by using the three dots &lt;strong&gt;...&lt;/strong&gt; and the &lt;strong&gt;nameOfparameter&lt;/strong&gt;, all arguments will be thrown into the array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--baYOoqIC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://2n.pl/ckeditor_assets/pictures/92/content_es5-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--baYOoqIC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://2n.pl/ckeditor_assets/pictures/92/content_es5-1.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, we must take care that the rest parameter is used correctly, always at the end of the parameters passed. This is since, it will not just work. The error we receive will certainly remind us of it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DSDPzCRo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://2n.pl/ckeditor_assets/pictures/93/content_es5-3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DSDPzCRo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://2n.pl/ckeditor_assets/pictures/93/content_es5-3.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  SPREAD
&lt;/h2&gt;

&lt;p&gt;It allows an array of arguments for elements calls (for array calls) or elements (for array literals) are expected or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected. Sounds complicated? Let's look at a few examples of how we will use it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nHsSa-Zm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ik326f5yvqima7xi9ct7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nHsSa-Zm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ik326f5yvqima7xi9ct7.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e-ZZ7Jyu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://2n.pl/ckeditor_assets/pictures/94/content_es5-5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e-ZZ7Jyu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://2n.pl/ckeditor_assets/pictures/94/content_es5-5.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can observe with great ease we can combine the arrays.&lt;/p&gt;

&lt;p&gt;In the next post, I will talk about array helper methods so stay tuned! Thank's for reading and don't hesitate to express your opinion on this post - all of your feedback will be appreciated :). &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Top project management tools</title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Thu, 09 May 2019 13:53:59 +0000</pubDate>
      <link>https://forem.com/2nit/top-6-project-management-tools-4fgi</link>
      <guid>https://forem.com/2nit/top-6-project-management-tools-4fgi</guid>
      <description>&lt;p&gt;As I mentioned in one of the &lt;a href="https://www.2n.pl/blog/managing-projects-with-graphql-editor" rel="noopener noreferrer"&gt;previous articles&lt;/a&gt;, managing projects is not an easy task. Thankfully, there are plenty of project management tools out there which can be really helpful in organizing work.  But the huge amount of different options could make it hard and confusing to choose the tool that will fit your's team the best. That's why I made this list of best (in my opinion) tools for project management.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Pivotal Tracker
&lt;/h2&gt;

&lt;p&gt;A &lt;a href="https://www.pivotaltracker.com/" rel="noopener noreferrer"&gt;Pivotal Tracker&lt;/a&gt; is a simple story-based tool that helps prioritize tasks with customer participation. Through a joint vision of priorities, it allows creating a work process that favors collaboration. A huge strength of Pivotal Tracker is the ability to monitor your project's analytics (it's velocity, done stories, story cycle time and story rejection rate). Pivotal Tracker calculates the velocity on the basis of the average number of story points completed during the last one to four iterations. Based on those, Pivotal Tracker predicts the number of repetitions of the story that will be completed. That's my personal favorite, but there are many more that I find useful. &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%2F6mu95t1vc8i3i02soigu.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%2F6mu95t1vc8i3i02soigu.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Trello
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://trello.com/" rel="noopener noreferrer"&gt;Trello&lt;/a&gt; is a tool for organizing project using boards. Its visual representation of tasks helps to see what your current assignment is, who is doing what and where individual tasks are placed in the process and it does it really well. This easily enables the coordination of a project. &lt;a href="https://trello.com/" rel="noopener noreferrer"&gt;Trello&lt;/a&gt; could be used for collaboration within a wide range of different projects, from work projects to holiday planning, thanks to its accessibility and user-friendly interface. &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%2Fibx5co07ln6dnixfe6fy.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%2Fibx5co07ln6dnixfe6fy.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Insightly
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.insightly.com/" rel="noopener noreferrer"&gt;Insightly&lt;/a&gt; is a robust CRM software. While it focuses the most on developing stronger client relationships (of course), this tool includes a really comprehensive set of project and business management systems. &lt;a href="https://www.insightly.com/" rel="noopener noreferrer"&gt;Insightly&lt;/a&gt; allows you to manage your around-sales operations and schedule deadlines and easily track progress. Your assignments may take whatever form you want - reminders, checklists,  call lists, etc. &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%2Fxyzbzfagbb0flam9e7a0.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%2Fxyzbzfagbb0flam9e7a0.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Workzone
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.workzone.com/" rel="noopener noreferrer"&gt;Workzone&lt;/a&gt; is project management and document collaboration app which helps people and companies achieve enhanced scrutiny and visibility in their work management. It allows users to arrange projects by tasks, delegate duties, and announce when they are finished. This tool gives an option to join together tasks to learn about how a modification in one area changes the rest of the work process. &lt;a href="https://www.workzone.com/" rel="noopener noreferrer"&gt;Workzone&lt;/a&gt; will notify you when tasks are delayed and allows project managers to rapidly recognize projects that demand urgent action.&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%2Fb5b813cni1tgzhf90y47.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%2Fb5b813cni1tgzhf90y47.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. nTask
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.ntaskmanager.com/" rel="noopener noreferrer"&gt;nTask&lt;/a&gt; is a relatively new project management tool but it stands its ground by assembling most of the utilities used by the teams on a daily basis into one agile platform for cooperation like a project, time, resource, issue, risk and meetings management. A big advantage of this tool is also a  comparatively low price (and a complex free plan), which can be significant in the case of small teams or companies.&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%2Ft9pn6gdfa9qyzw0va29w.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%2Ft9pn6gdfa9qyzw0va29w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. JIRA
&lt;/h2&gt;

&lt;p&gt;It would be a sin not to mention &lt;a href="https://www.atlassian.com/software/jira" rel="noopener noreferrer"&gt;JIRA&lt;/a&gt; in this article. &lt;a href="https://www.atlassian.com/software/jira" rel="noopener noreferrer"&gt;JIRA&lt;/a&gt; is very popular and very powerful project management software used by many companies worldwide. It makes it easy to create user stories, to plan tasks assigned to your team members, and to prioritize the order in which they are being implemented while maintaining full visibility. Its usage is not complicated, so you can just jump into &lt;a href="https://www.atlassian.com/software/jira" rel="noopener noreferrer"&gt;JIRA&lt;/a&gt; and start managing your projects right away - regardless of whether your project is quite simple or complex. &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%2Funukighcvcuonqntmz8v.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%2Funukighcvcuonqntmz8v.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Teamwork Projects
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.teamwork.com/project-management-software/" rel="noopener noreferrer"&gt;Teamwork Projects&lt;/a&gt; is an intuitive, feature-rich project management tool that lets you reduce the complexity of collaboration. It takes care of the everyday details so you can focus on the work that matters — and own the big picture. Whether you need task lists, Kanban boards or Gantt charts, Teamwork Projects has all the features you need to empower your team, optimize your resources and deliver results that make a difference to the big picture.&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%2Fgmhfw7idmyw78v126faa.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%2Fgmhfw7idmyw78v126faa.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Milanote
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://milanote.com/" rel="noopener noreferrer"&gt;Milanote&lt;/a&gt; is a tool for organizing creative projects into beautiful visual boards. By design, it feels a lot like working on the wall in a creative studio - visual, tactile and sometimes a bit messy - Milanote is a great fit for designers who work in teams remotely.&lt;/p&gt;

&lt;p&gt;Key Features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write notes &amp;amp; to-do lists, upload images &amp;amp; files and save things you find on the web&lt;/li&gt;
&lt;li&gt;Organize visually using the flexible drag and drop interface.&lt;/li&gt;
&lt;li&gt;Boards by default are a private place to think, but with a single click you can create a shared workspace for collaboration with your team&lt;/li&gt;
&lt;li&gt;Milanote is filled with hundreds of built-in templates to help you get started with a variety of different projects, from creating a mood board to writing that perfect creative brief.&lt;/li&gt;
&lt;/ul&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%2Fb9kqfc4tnpc4d7l45mb8.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%2Fb9kqfc4tnpc4d7l45mb8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, there are many, many more of other project management tools. A lot of them might prove to be useful for you and your team or fit your's company needs better.  It's all about knowing available options and finding the one that works the best for you. &lt;/p&gt;

</description>
      <category>productivity</category>
      <category>beginners</category>
      <category>leadership</category>
    </item>
    <item>
      <title>ES6 for beginners - part 3 (Classes) </title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Fri, 12 Apr 2019 14:04:42 +0000</pubDate>
      <link>https://forem.com/2nit/es6-for-beginners-part-3-classes-bcj</link>
      <guid>https://forem.com/2nit/es6-for-beginners-part-3-classes-bcj</guid>
      <description>&lt;p&gt;&lt;em&gt;I want to present the third part of the series "ES6 for beginners" created by one of our devs, Bartosz. You can find the previous parts &lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Before we start discussing &lt;em&gt;Classes&lt;/em&gt; in JavaScript, one thing needs to be explained. Classes in JavaScript are more like syntactic sugar than the new feature. Nevertheless, as in the case of Arrow Function about which I wrote in the &lt;a href="https://www.2n.pl/blog/es6-part-2" rel="noopener noreferrer"&gt;previous section&lt;/a&gt;, this is a facility worth remembering.&lt;/p&gt;

&lt;p&gt;One of the worst parts in JavaScript is undoubtedly the inheritance system. JavaScript does not really have object inheritance, but something called prototypal inheritance. Class inheritance has been introduced to JavaScript due to the fact that it occurs in the vast majority of programming languages.&lt;/p&gt;

&lt;p&gt;So what are &lt;em&gt;Classes&lt;/em&gt; in JavaScript except for syntactic sugar, which leads to a more readable syntax? The answer is simple and the same as in other object-oriented programming languages. They are to create objects. They are like blueprints, on the basis of which objects are created. In addition, JavaScript classes are basically special functions.&lt;/p&gt;

&lt;p&gt;The class declaration consists of two parts. The expression &lt;em&gt;class&lt;/em&gt; and &lt;em&gt;class declaration&lt;/em&gt;. Example below.&lt;br&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%2F7ysg1bnvap7ojicmsop9.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%2F7ysg1bnvap7ojicmsop9.png"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Nothing complicated. But now let's look at what will happen as in the console &lt;em&gt;typeof Dog&lt;/em&gt;.&lt;br&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%2F5jtsfekpuqms1nunk893.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%2F5jtsfekpuqms1nunk893.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Exactly as I mentioned. Our class is a function by which we will later create objects.&lt;/p&gt;

&lt;p&gt;There are still a few things missing in our &lt;em&gt;Dog&lt;/em&gt; class. The first one will be a &lt;em&gt;Constructor&lt;/em&gt;. This is a special keyword used to initialize the object data. A &lt;em&gt;Constructor&lt;/em&gt; can accept any number of parameters. In our example, we will create two (&lt;em&gt;name&lt;/em&gt; and &lt;em&gt;height&lt;/em&gt;). Then, using variable &lt;em&gt;this&lt;/em&gt;, we will ensure that the arguments passed in the parameters will be saved in the variables. In our case, also with the same names. Of course, it is possible to name the classy property differently than the parameter, as in the example below, however, it is not very legible and not recommended.&lt;br&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%2Fbe32vu80yfq9vz7sh2t3.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%2Fbe32vu80yfq9vz7sh2t3.png"&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%2F9ejbrlw1hytszxvm5yiw.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%2F9ejbrlw1hytszxvm5yiw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But let's return to the normal way of doing things.&lt;br&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%2F05g8oav9sxkrzntxfqbg.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%2F05g8oav9sxkrzntxfqbg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we have a created class, we can boldly create any number of objects/instances of this class. The way we do it is as follows.&lt;br&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%2Frjtom5hvh7x4iu2t2ktx.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%2Frjtom5hvh7x4iu2t2ktx.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The name of our object in this example will be &lt;em&gt;Staffie&lt;/em&gt;. Next, we pass to parameters that we defined in the constructor two arguments. The first &lt;em&gt;"Bur"&lt;/em&gt; will be our &lt;em&gt;name&lt;/em&gt;, the second &lt;em&gt;60&lt;/em&gt; will be the &lt;em&gt;height&lt;/em&gt;.&lt;br&gt;
Also, we can create methods in classes. The method is just a function that is placed inside the class. So let's add a method that will return the sound of barking.&lt;br&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%2Fogx12n0caxx52m983le6.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%2Fogx12n0caxx52m983le6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our &lt;em&gt;Staffie&lt;/em&gt; has the option of using this method. When we call the barking method in the console, we get:&lt;br&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%2Fwdf2wyatrvowfohsxv18.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%2Fwdf2wyatrvowfohsxv18.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since we know how to create classes, let's look at the &lt;em&gt;inheritance&lt;/em&gt;. Since the dogs are divided not only by races but also groups, let's create a &lt;em&gt;Terrier&lt;/em&gt; class that will inherit from the &lt;em&gt;Dog&lt;/em&gt; class. It is also not complicated.&lt;br&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%2F0rs2pmd803eks82htdwb.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%2F0rs2pmd803eks82htdwb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, we see that to be able to inherit from another class, we use the word &lt;em&gt;extends&lt;/em&gt; + &lt;em&gt;the name of the class&lt;/em&gt; from which we want to inherit. Besides, we see keyword &lt;em&gt;super&lt;/em&gt;. It allows us using the special variable &lt;em&gt;this&lt;/em&gt; and have access when creating an instance of the &lt;em&gt;Terrier&lt;/em&gt; class to the &lt;em&gt;name&lt;/em&gt; and &lt;em&gt;height&lt;/em&gt; parameters which are inherited from &lt;em&gt;Dog&lt;/em&gt; class.&lt;br&gt;
Another thing that is often encountered is when we want to use our method &lt;em&gt;barking&lt;/em&gt; in the case of Terriers. However, the returned value would be something different than in a regular dog.&lt;br&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%2Fsb7g9qm47fo2oxrba22z.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%2Fsb7g9qm47fo2oxrba22z.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, there is no magic in it. Now our terrier &lt;em&gt;Tommy&lt;/em&gt; will be barking in a way that any self-respecting terrier does.&lt;br&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%2Ftf0nelh4ho3axctjpehc.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%2Ftf0nelh4ho3axctjpehc.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Generally, convention from languages ​​like Java in which there is an object-oriented programming model also assumes holding classes in different files. Namely, instead of just like in our example one file with two classes, a better solution would be to transfer them to two separate files. Thanks to such a procedure, our code would become much more readable which is a great advantage when writing.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Dog&lt;/em&gt; class&lt;br&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%2Fxxap5cezopvdbe9lmj07.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%2Fxxap5cezopvdbe9lmj07.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Terrier&lt;/em&gt; class&lt;br&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%2Fgob44ogjy6bsqgbnk43s.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%2Fgob44ogjy6bsqgbnk43s.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see we used two keywords. &lt;em&gt;Import&lt;/em&gt; and &lt;em&gt;Export&lt;/em&gt;. As you probably already figured out what they are used for. I will only mention that you can export functions, objects, or primitive values from the module so other programs with the &lt;strong&gt;import&lt;/strong&gt; statement can use them.&lt;/p&gt;

&lt;p&gt;Another topic worth mentioning in this part is the static methods. So what are they exactly? First of all, they are created with a keyword static. The most important thing about them is that they are called directly on the class and are not callable on an instance of the class. Their purpose is to create a utility function.&lt;br&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%2Fr9ztbnxo6rcqs6n33sr5.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%2Fr9ztbnxo6rcqs6n33sr5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We created an instance of &lt;em&gt;Dog&lt;/em&gt; class and named it &lt;em&gt;Staffie&lt;/em&gt; once again. Let's try to invoke both methods.&lt;br&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%2F03cejwaj59ckm4vz3b2g.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%2F03cejwaj59ckm4vz3b2g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, the method &lt;em&gt;barking&lt;/em&gt; works as intended. Now let's invoke the second one.&lt;br&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%2Fatydv8qnzsgpn63t0gif.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%2Fatydv8qnzsgpn63t0gif.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see it works as intended too. We can't invoke a static function on the object. On another hand is it possible to invoke it on the class as its supposed to?&lt;br&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%2Fcu2c2pve0sgujg5olkcp.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%2Fcu2c2pve0sgujg5olkcp.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great, it does.&lt;/p&gt;

&lt;p&gt;So, did JavaScript after the introduction of the ES6 standard start to belong to languages ​​that use the Object-Oriented Programming (OOP) model? The answer is, it does not. JavaScript is still based on the Prototypal inheritance model.&lt;/p&gt;

&lt;p&gt;In the next post we'll talk about rest &amp;amp; spread.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>ES6 for beginners - part 2 (Arrow Functions)</title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Fri, 05 Apr 2019 13:49:56 +0000</pubDate>
      <link>https://forem.com/2nit/es6-for-beginners-part-2-arrow-functions-15ja</link>
      <guid>https://forem.com/2nit/es6-for-beginners-part-2-arrow-functions-15ja</guid>
      <description>&lt;p&gt;&lt;em&gt;I want to present to you the second part of the blog posts series "ES6 for beginners" written by our dev, Bartosz. You can find the previous part &lt;a href="https://www.2n.pl/blog/es6-part-1" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We all wrote a lot of functions but let's start with a simple one that adds two arguments.&lt;br&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%2Fzgb9ifsj29b6wx2vi3tw.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%2Fzgb9ifsj29b6wx2vi3tw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, everything is correct and compliant with ES5 standards. At the outset, I will also point out that if someone liked a syntax in how the functions in JavaScript were created so far, they do not have to change everything. The ES5 way is as correct as it was but ES6 has some facilities that can make life a bit easier.&lt;/p&gt;

&lt;p&gt;Now a code sample on how we would write it following with ES6 standards.&lt;br&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%2Fgemqkg3moixxqxh0ph8t.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%2Fgemqkg3moixxqxh0ph8t.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, two things have changed. First of all, we took out the keyword &lt;em&gt;function&lt;/em&gt;, and secondly, we added the &lt;em&gt;Arrow Function ( =&amp;gt; )&lt;/em&gt; after the parameters. By some people, it is also called the &lt;em&gt;Fat Arrow Function&lt;/em&gt;. This indicates that the arrow is created using an &lt;em&gt;equal&lt;/em&gt; sign. An interesting fact is also that there is a so-called &lt;em&gt;thin-arrow&lt;/em&gt; in CoffeeScript. It differs in that instead of the &lt;em&gt;equal&lt;/em&gt; sign it appears as you probably guess the &lt;em&gt;dash&lt;/em&gt;.&lt;br&gt;
We could end here, and I would try to encourage everyone to switch to the new ES6 version. However, if someone wants to know quite an important difference, I encourage you to read a few more lines.&lt;/p&gt;

&lt;p&gt;We could try to do it in even more fancy way&lt;br&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%2Fxe1p9vzc7vc7myhfovv5.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%2Fxe1p9vzc7vc7myhfovv5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, let me use the function I have already shown in the previous series (&lt;a href="https://www.2n.pl/blog/javascript-part-16" rel="noopener noreferrer"&gt;JavaScript Part 16&lt;/a&gt;).&lt;br&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%2Ftd1qsh819fbcl63rtr98.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%2Ftd1qsh819fbcl63rtr98.png"&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%2Fajt8iq36r0qwz8xjf92m.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%2Fajt8iq36r0qwz8xjf92m.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can remember (or not) that for our last console.log to return a changed name for the second time, we had to use a trick that looked like this.&lt;br&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%2Fvrp7ru54rauoioob0nzn.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%2Fvrp7ru54rauoioob0nzn.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another way would be to use the bind function, which I wrote about in the last part of the previous series. It would look like this.&lt;br&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%2Fw1hqul3e1frl2way1yy5.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%2Fw1hqul3e1frl2way1yy5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In both of them, we would get what theoretically we want and theoretically how it should be.&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%2Fz90x46rwaqzei5xpd7br.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%2Fz90x46rwaqzei5xpd7br.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before I show you how simple and easy it is to get the desired effect (&lt;em&gt;this&lt;/em&gt; pointing to the object a function is in) let's modify primary code a bit .&lt;br&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%2Fa8ijpwb2t9xf2ohvtdd6.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%2Fa8ijpwb2t9xf2ohvtdd6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know, I know that's a lot of consoles.logs, but I find it as the best way to figure out what is happening at a given moment. Let's go. First console.log after invoking a doSomeNameMagic method ( myObject.doSomeNameMagic(); ) on the myObject will log us new value of myName. Since a doSomeNameMagic function is attached to the object (same way as myName), &lt;em&gt;this&lt;/em&gt; variable will point to the object it is attached. In our case - myObject.&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%2F3wrq81wcao6ddaoo275i.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%2F3wrq81wcao6ddaoo275i.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside the doSomeNameMagic function, we are doing a little bit more. The changeName function is created and invoked with an argument - "I changed myName once again !". So since we are invoking it let's check the results of 3 console.logs inside it.&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%2F23vjxzy69918g7gfftfv.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%2F23vjxzy69918g7gfftfv.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first thing that catches the eye (first line) is that the value &lt;em&gt;this&lt;/em&gt; points to a global object, not a myObject. This is how the so-called standalone functions behave. In our case, it will be a browser window object. Since this indicates the window object where there is no information about the variable myName, it should be obvious that the value we get is undefined. The last console.log, however, simply returns the value of the argument passed to changeName.&lt;/p&gt;

&lt;p&gt;The next console.log (in IIFE) will also point to the global object for the same reason as above - standalone function, which is simply the so-called IIFE (first picture below). Since in the changeName of the function there was no information about the variable myName, the change failed and the last console.log will simply return the old value (the second image below).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F23vjxzy69918g7gfftfv.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%2F23vjxzy69918g7gfftfv.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although in a moment we will go to Arrow Function, it is worth remembering how this works in javascript before introducing Arrow Functions. Often you will want to use the old syntax (for example Vue.js, but about that maybe next time).&lt;/p&gt;

&lt;p&gt;The third and most on-time way is to use just the &lt;em&gt;Arrow Function&lt;/em&gt;.&lt;br&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%2F2azqjw0uxp45e61cuz7j.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%2F2azqjw0uxp45e61cuz7j.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we decide to solve it using ES6, it is worth knowing how special variable this works. Well, it is quite simple, the Arrow Function does not have its own this value. This value takes on the value of what the Arrow Function is in. So for example, if We wrote a doSomeNameMagic function as an Arrow Function, this would point to ... You guessed - window object. Arrow Functions shine exactly in those moments when anything that requires this to be bound to the context and not the function itself.&lt;/p&gt;

&lt;p&gt;In the next post, we will talk about &lt;em&gt;Classes&lt;/em&gt; in ES6.&lt;/p&gt;

</description>
      <category>es6</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>ES6 for beginners - part 1 (Let, Const)</title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Thu, 28 Mar 2019 15:43:28 +0000</pubDate>
      <link>https://forem.com/2nit/es6-for-beginners-part-1-2mnm</link>
      <guid>https://forem.com/2nit/es6-for-beginners-part-1-2mnm</guid>
      <description>&lt;p&gt;&lt;em&gt;I want to present to you the first part of the blog posts series "ES6 for beginners" written by our dev, Bartosz. &lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&gt;Next parts coming soon!&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;In the beginning, I would like to congratulate everyone who has read some of my posts about &lt;a href="https://www.2n.pl/blog?tag=JavaScript+for+beginners" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Of course, there is nothing to prevent you from starting from here, but I think that understanding the &lt;a href="https://www.2n.pl/blog?tag=JavaScript+for+beginners" rel="noopener noreferrer"&gt;previous parts&lt;/a&gt; is much more important than reading about the new features in ES6. However, if you would like to start right away from this place, nothing stands in the way&lt;/p&gt;

&lt;p&gt;Topics that I will touch are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;let / const&lt;/li&gt;
&lt;li&gt;arrow functions&lt;/li&gt;
&lt;li&gt;classes&lt;/li&gt;
&lt;li&gt;spread operator/rest parameter&lt;/li&gt;
&lt;li&gt;destructuring&lt;/li&gt;
&lt;li&gt;array helper methods&lt;/li&gt;
&lt;li&gt;promises/fetch&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Ok, for starters, what ES6 is?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;ES6 is basically ECMAScript 6 / ECMAScript 2015. ECMAScript is not any scripting language instead of a standard that Javascript is based upon. So, ES6 is a new version or new standard of JavaScript. ES6 brings many new features like the concept of classes, arrow functions etc. Almost all the modern browsers support ES6 but for the old browsers, there are many transpilers e.g. Babel.js those we need to include at top of our code to transpile ES6 to ES5 (JavaScript with old standards). All of the popular JavaScript libraries and frameworks like Node.js, ReactJS follow ES6.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;We will start with something very simple but also very useful. &lt;em&gt;Let&lt;/em&gt; and &lt;em&gt;Const&lt;/em&gt;.&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;We all know what the &lt;em&gt;var&lt;/em&gt; keyword is. We have used it many times. New variable? &lt;em&gt;var&lt;/em&gt;, new Function Expression? &lt;em&gt;var&lt;/em&gt; etc. ES6 introduces two additional keywords, which are &lt;em&gt;let&lt;/em&gt; and &lt;em&gt;const&lt;/em&gt;. This does not mean that &lt;em&gt;var&lt;/em&gt; will stop working now, but you are very encouraged to use the new ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;let&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Short, It is really a new &lt;em&gt;var&lt;/em&gt;. Let is encouraged to be used everywhere instead of the mentioned &lt;em&gt;var&lt;/em&gt;. By everywhere I mean anywhere except when we want to use &lt;em&gt;const&lt;/em&gt; (explanation is few lines below). Use &lt;em&gt;let&lt;/em&gt; for example if you want to create a simple variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpvbjywnypdarob8mwtyv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpvbjywnypdarob8mwtyv.png" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa252gp327g7xcomv9b64.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa252gp327g7xcomv9b64.png" width="504" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in this example, there is no difference. A logical question now would be, if there is no difference, why was it introduced to JavaScript?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftuel0frvhpddv1kjcl5s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftuel0frvhpddv1kjcl5s.png" width="800" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's follow another example. Here we can see the function which contains two &lt;em&gt;for loops&lt;/em&gt;. The only difference is exactly the &lt;em&gt;var&lt;/em&gt; and the &lt;em&gt;let&lt;/em&gt;. However, if we want to check the values of &lt;em&gt;I&lt;/em&gt; and &lt;em&gt;j&lt;/em&gt; in the console, outside the block where the code is executed, we will get two different results.&lt;/p&gt;

&lt;p&gt;When &lt;em&gt;var i = 0&lt;/em&gt;, our &lt;em&gt;i&lt;/em&gt; variable will be visible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F95527jd30xhkl17ziif7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F95527jd30xhkl17ziif7.png" width="493" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, if we use &lt;em&gt;let j = 0&lt;/em&gt;, our &lt;em&gt;j&lt;/em&gt; variable will not be visible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe1ume2gpoac048c7mdb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe1ume2gpoac048c7mdb3.png" width="494" height="45"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;const&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The main reason we want to use the &lt;em&gt;const&lt;/em&gt; keyword is when we don't want a variable to be re-declared in later code. For example, I strongly recommend using treat &lt;em&gt;const&lt;/em&gt; like an old &lt;em&gt;var&lt;/em&gt; and change to let when it is needed. Let's see what will happen when we decide to change the variable that we declared using a &lt;em&gt;const&lt;/em&gt; keyword.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx7u710yneufr2uw2jmv6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx7u710yneufr2uw2jmv6.png" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgc1dapq5xxkr0afuiwsk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgc1dapq5xxkr0afuiwsk.png" width="494" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Error :)&lt;/p&gt;

&lt;p&gt;Of course, it is still possible to use methods such as &lt;em&gt;push&lt;/em&gt; etc, but as shown above, any "manual" change of the previously declared value will end with an error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsccooujp4wx3detm22s8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsccooujp4wx3detm22s8.png" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptvrhvwpf0huhca7g9d9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptvrhvwpf0huhca7g9d9.png" width="493" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our array has been modified.&lt;/p&gt;

&lt;p&gt;In the next article, we will discuss another topic from the list: Arrow Functions.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&gt;Next Post will be published soon!&lt;/a&gt;
&lt;/h4&gt;

</description>
      <category>es6</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JavaScript - Bind, Call, Apply</title>
      <dc:creator>Łukasz Żarski</dc:creator>
      <pubDate>Thu, 21 Mar 2019 13:13:13 +0000</pubDate>
      <link>https://forem.com/2nit/javascript---bind-call-apply-52ka</link>
      <guid>https://forem.com/2nit/javascript---bind-call-apply-52ka</guid>
      <description>&lt;p&gt;&lt;em&gt;That's actually a 20 part of blog posts series &lt;a href="https://www.2n.pl/blog?tag=JavaScript+for+beginners_" rel="noopener noreferrer"&gt;"JavaScript for beginners"&lt;/a&gt; created by our dev Bartosz. All of the parts are available at &lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&gt;2n.pl&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The function is a special type of object and has several properties. We already discussed it in one of the &lt;a href="https://www.2n.pl/blog/javascript-part-14" rel="noopener noreferrer"&gt;previous parts&lt;/a&gt;. To better understand what we are going to deal with today, let's start with an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&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%2Fnpn3gskylh0ngo3dgc14.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After invoking a function, we will receive:&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%2Flz1gfcp0dh3myqxsx2pp.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%2Flz1gfcp0dh3myqxsx2pp.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What's wrong here?&lt;br&gt;
Of course, the fact that in invoking the &lt;em&gt;logName&lt;/em&gt; function, the JavaScript engine does not see the &lt;em&gt;getFullName&lt;/em&gt; method, which is assigned to the &lt;em&gt;person&lt;/em&gt; object. In that case, wouldn't it be nice and pleasant to have such access?&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;bind&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&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%2Ft6e7e8yks3w8z0ojaf1s.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, we used the &lt;em&gt;bind&lt;/em&gt; function.&lt;/p&gt;

&lt;p&gt;Thanks to this function, all we did was that we combined Function Expression &lt;em&gt;logName&lt;/em&gt; with the &lt;em&gt;person&lt;/em&gt; Object, and the whole thing was saved in the &lt;em&gt;logPersonName&lt;/em&gt; variable. But how does it really work? Well, the bind function creates a new copy of the &lt;em&gt;logName&lt;/em&gt; function. By passing the object, &lt;em&gt;person&lt;/em&gt;, we have an influence on what we want our copy to "combine" with. The &lt;em&gt;this&lt;/em&gt; variable in the &lt;em&gt;logName&lt;/em&gt; Function Expression will refer to the object that we passed. As it is really only a copy, we can invoke it, as we do in the eighteenth line.&lt;/p&gt;

&lt;p&gt;As you can see, this is quite useful when you want to access the object in a function outside that object.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;call&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;This function is very similar to the &lt;em&gt;bind&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&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%2Fiin74zob4tp6q8r7igt0.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we called the &lt;em&gt;call&lt;/em&gt; function on &lt;em&gt;logName&lt;/em&gt; and passed the person. The result will be identical but in this case, no copy of the &lt;em&gt;logName&lt;/em&gt; function is created, but the &lt;em&gt;logName&lt;/em&gt; function itself is invoked. In fact, &lt;em&gt;logName.call&lt;/em&gt; is the same as &lt;em&gt;logName()&lt;/em&gt;, which is invoking a function. However, using the &lt;em&gt;call&lt;/em&gt; function we have a greater ability to influence what we want to achieve, we have an influence on whether &lt;em&gt;this&lt;/em&gt; variable is. Of course, we can also pass two arguments to the parameters &lt;em&gt;part1&lt;/em&gt; and &lt;em&gt;part2&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&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%2Fan7z8a856dd1sy0ej7u7.png"&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%2Fzuvpthc5bjdsgx9lbi76.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%2Fzuvpthc5bjdsgx9lbi76.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;apply&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&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%2F8al3r818fwuddugvryzl.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we have another function that is similar to the rest. Using it, we also control what the special variable &lt;em&gt;this&lt;/em&gt; is supposed to be, but we pass the arguments in an array. Probably now the question comes to mind, what is the actual use of it in real life?&lt;/p&gt;

&lt;p&gt;The first case is the so-called &lt;em&gt;function borrowing&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&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%2Fczm9fd3g6dkvacdscfkq.png"&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%2Ft2xfh77frqthtm7hr360.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%2Ft2xfh77frqthtm7hr360.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can observe that despite using the &lt;em&gt;getFullName&lt;/em&gt; method on the person object, we received &lt;em&gt;"Tom Goe"&lt;/em&gt;. This is because we have manipulated what the special variable &lt;em&gt;this&lt;/em&gt; is. As the return value from the &lt;em&gt;getFullName&lt;/em&gt; method is the variable &lt;em&gt;fullName&lt;/em&gt;, and in it, we indicate through variable this that &lt;em&gt;firstName&lt;/em&gt; and &lt;em&gt;lastName&lt;/em&gt; are to refer to the object on which it is called.&lt;/p&gt;

&lt;p&gt;The next case is the &lt;em&gt;function currying&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&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%2Fkzo8lg5ellcvzbfs5siy.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This example is related to &lt;em&gt;bind&lt;/em&gt;, because then a copy of the function is created.&lt;/p&gt;

&lt;p&gt;It is also not complicated. In the &lt;em&gt;bind&lt;/em&gt; function, first of all, we pass to what the special variable &lt;em&gt;this&lt;/em&gt; is supposed to refer to. Then we set permanently what will be the first parameter, in our case &lt;em&gt;a&lt;/em&gt;. As the result &lt;em&gt;a * b&lt;/em&gt; is returned, and &lt;em&gt;a&lt;/em&gt; is always equal 2. At the time of the invocation of the function, we give only what &lt;em&gt;b&lt;/em&gt; parameter should be equal to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.2n.pl/blog" rel="noopener noreferrer"&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%2Fb0dp0601tex6uumkeird.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, if we passed 10 instead of 5, we would get 20. And so on :). &lt;/p&gt;

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