<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Somnath Singh</title>
    <description>The latest articles on DEV Community by Somnath Singh (@polymathsomnath).</description>
    <link>https://dev.to/polymathsomnath</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%2F480024%2Ff74a643f-07f7-4194-b3a7-6fcfe633c8ad.jpeg</url>
      <title>DEV Community: Somnath Singh</title>
      <link>https://dev.to/polymathsomnath</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/polymathsomnath"/>
    <language>en</language>
    <item>
      <title>The Story of AI: From Brain Cells to ChatGPT(… and what it really wants)</title>
      <dc:creator>Somnath Singh</dc:creator>
      <pubDate>Fri, 11 Jul 2025 08:35:10 +0000</pubDate>
      <link>https://dev.to/polymathsomnath/the-story-of-ai-from-brain-cells-to-chatgpt-and-what-it-really-wants-22k9</link>
      <guid>https://dev.to/polymathsomnath/the-story-of-ai-from-brain-cells-to-chatgpt-and-what-it-really-wants-22k9</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7zo8u3iavojttw1dkn7b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7zo8u3iavojttw1dkn7b.jpg" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;it was 1943. &lt;/p&gt;

&lt;p&gt;world war II was raging. &lt;/p&gt;

&lt;p&gt;meanwhile two guys - mcculloch and pitts - sat down and asked a weird &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;question: can we describe the brain… using math?&lt;/strong&gt;&lt;br&gt;
the first time we tried to make a machine think… we weren't building computers.&lt;/p&gt;

&lt;p&gt;we were trying to decode ourselves.&lt;/p&gt;

&lt;p&gt;they weren't coding. they were dreaming.&lt;br&gt;
they imagined a network of simple units - on or off - just like neurons.&lt;/p&gt;

&lt;p&gt;it didn't do much. it couldn't learn. but it was enough to start a fire.&lt;/p&gt;

&lt;p&gt;they sparked a new kind of thinking…&lt;/p&gt;

&lt;p&gt;one where intelligence wasn't magic or soul or mystery…&lt;br&gt;
but computation.&lt;/p&gt;

&lt;p&gt;fast forward to 1950s…&lt;br&gt;
alan turing asked, can machines think?&lt;/p&gt;

&lt;p&gt;but nobody could even define "thinking."&lt;/p&gt;

&lt;p&gt;in the 60s, we tried rule-based logic.&lt;/p&gt;

&lt;p&gt;in the 80s, we returned to neural nets.&lt;/p&gt;

&lt;p&gt;in the 2000s, we gave up again.&lt;br&gt;
**&lt;br&gt;
then came 2012.**&lt;/p&gt;

&lt;p&gt;a deep net beat everyone at recognizing cats on the internet.&lt;br&gt;
the floodgates opened.&lt;/p&gt;

&lt;p&gt;we taught sand to dream in probabilities.&lt;/p&gt;

&lt;p&gt;we made silicon hallucinate.&lt;/p&gt;

&lt;p&gt;we layered millions of artificial neurons and whispered billions of words into them.&lt;/p&gt;

&lt;p&gt;today, we have chatgpt.&lt;/p&gt;

&lt;p&gt;tomorrow… god knows what.&lt;/p&gt;

&lt;p&gt;that's why i have created boringskool. &lt;/p&gt;

&lt;p&gt;we're not here to predict the future.&lt;/p&gt;

&lt;p&gt;we're here to trace how we got here… and how to ride the next wave with eyes wide open.&lt;/p&gt;

&lt;p&gt;our first video is out now. it's not a tutorial. it's a story.&lt;/p&gt;

&lt;p&gt;the truth is, this isn't just about ai.&lt;br&gt;
it's about you.&lt;br&gt;
your attention. &lt;br&gt;
your curiosity. &lt;br&gt;
your ability to still be surprised.&lt;br&gt;
watch the story.&lt;/p&gt;

&lt;p&gt;and then ask yourself:&lt;br&gt;
are you still sleepwalking through this era…&lt;br&gt;
or are you finally waking up?&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/DRU-0tHOayc"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;this is the first video i've ever put out. and if you're reading this… &lt;/p&gt;

&lt;p&gt;it means the world. seriously. your support right now isn't just clicks or views… it's momentum. &lt;/p&gt;

&lt;p&gt;it's what keeps this thing going. &lt;br&gt;
boringskool isn't backed by some big team or fancy funding… &lt;br&gt;
it's just an idea i believe in. for the lazy and ambitious ones. &lt;/p&gt;

&lt;p&gt;for the misfits trying to stay relevant in the ai storm. &lt;/p&gt;

&lt;p&gt;so if this video hits something in you… share it, talk about it, reply. &lt;/p&gt;

&lt;p&gt;this is just the beginning.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>machinelearning</category>
      <category>learning</category>
    </item>
    <item>
      <title>Struggling with Promises? You Are Not Alone!</title>
      <dc:creator>Somnath Singh</dc:creator>
      <pubDate>Sun, 03 Jul 2022 13:19:09 +0000</pubDate>
      <link>https://dev.to/polymathsomnath/struggling-with-promises-you-are-not-alone-530g</link>
      <guid>https://dev.to/polymathsomnath/struggling-with-promises-you-are-not-alone-530g</guid>
      <description>&lt;p&gt;Do you like to cook? I’m not sure about you, but I enjoy cooking. I usually cook by myself, although I’m not opposed to having some help.&lt;/p&gt;

&lt;p&gt;Many times you’ll find yourself in a situation where you will need something in the middle of cooking and that damn thing isn’t in your house and you have to ask someone to get it for you while you’re cooking. In the meantime, you keep doing your job!&lt;/p&gt;

&lt;p&gt;You may be familiar with this way of doing things — in programming languages — we refer to it as &lt;strong&gt;&lt;em&gt;asynchronous.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We often do things asynchronously in programming. That is we initiate something and before even it completes we initiate some other task.&lt;/p&gt;

&lt;p&gt;In JavaScript, we rely a lot on asynchronous operations — whose results we don’t have yet but will at some later point.&lt;/p&gt;

&lt;p&gt;JavaScript in itself is not asynchronous but it supports asynchronous programming.&lt;/p&gt;

&lt;p&gt;ES6 has introduced an idea that makes handling asynchronous tasks easier: &lt;strong&gt;&lt;em&gt;Promises&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A promise is an object — a &lt;strong&gt;placeholder&lt;/strong&gt; for the eventual result.&lt;/p&gt;

&lt;p&gt;It is not that we could not do the async operation before. We did!&lt;/p&gt;

&lt;p&gt;All we had to do is to make use of Callbacks in a certain way! Doing so was a torture when we needed to do a task when our operation failed.&lt;/p&gt;

&lt;p&gt;Promises standardized the way to deal with &lt;strong&gt;&lt;em&gt;asynchronous events&lt;/em&gt; *&lt;em&gt;and *&lt;/em&gt;&lt;em&gt;callbacks&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I’ve seen people struggling with promises. This post aims to assist individuals in comprehending this amazing topic. We will endeavour to gain a proper mental model of promises through real-life examples.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The more you struggle to understand, the less you understand any problem. To understand, the mind must be quiet.&lt;/p&gt;

&lt;p&gt;— Jiddu Krishnamurti&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since people forget things but remember stories.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let us understand promises with this little story
&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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AWhZJwK8xvjdDGnsnlAESKg.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AWhZJwK8xvjdDGnsnlAESKg.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2Aco3JdR-Qq5BB1ds7CaQtog.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2Aco3JdR-Qq5BB1ds7CaQtog.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am not yet a master storyteller! However, the preceding scenario contains all of the necessary information to help you comprehend the concepts of Promises.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let us take the key points from it and apply them to JavaScript World.
&lt;/h2&gt;

&lt;p&gt;We need a standard description of what a Promise is — nothing better than MDN.&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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AoJVZUT9eDxjcmmxTr7tORg.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AoJVZUT9eDxjcmmxTr7tORg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us see, how this definition relates to our story.&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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AFtNMSdpZsKwT1nIDEgSx7Q.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AFtNMSdpZsKwT1nIDEgSx7Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The definition makes a lot more sense now!&lt;/p&gt;

&lt;p&gt;In JavaScript, a &lt;strong&gt;&lt;em&gt;Promise&lt;/em&gt;&lt;/strong&gt; is just an object. It is a &lt;strong&gt;&lt;em&gt;placeholder&lt;/em&gt;&lt;/strong&gt; for a value we do not have right now but will have later. It ensures that we will eventually know the result of an asynchronous operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Circumstances do not matter — only your state of being matters — what state of being are you choosing?
&lt;/h2&gt;

&lt;p&gt;A promise is nothing more than an object, and it is usual for objects to retain a state. By modifying the state, we do many complex tasks in programming.&lt;/p&gt;

&lt;p&gt;A promise is always in one of the three states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;pending:&lt;/strong&gt; which is the initial state — that is neither fulfilled nor rejected.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;fulfilled:&lt;/strong&gt; meaning that the operation was completed successfully.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;rejected:&lt;/strong&gt; meaning that the operation failed.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A7pNnd_1UDwypRvzeYg9LKw.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A7pNnd_1UDwypRvzeYg9LKw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us establish a strong mental model by tying the underlying &lt;em&gt;principles to our tale&lt;/em&gt; before diving into the 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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AJHbrtdV0UnagP1QaV1m36w.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AJHbrtdV0UnagP1QaV1m36w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How to work with promises?
&lt;/h1&gt;

&lt;p&gt;If we want to use promise in our code, then we must first understand these three fundamental concepts.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;How a to create Promise?&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;How to Fulfil or Reject a Promise?&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;How to Run a Callback Function — Depending on Whether the Promise Is &lt;em&gt;Resolved&lt;/em&gt; or &lt;em&gt;Rejected.&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“It is not the answer that enlightens, but the question.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;— Eugene Ionesco&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you understand these three things, dealing with promises will be a breeze.&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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2At9HAhA9ehDB7D14dFAuWzg.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2At9HAhA9ehDB7D14dFAuWzg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s take a look at each one individually.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to create a&lt;/strong&gt; Promise*&lt;em&gt;?&lt;/em&gt;*
&lt;/h2&gt;

&lt;p&gt;We create an instance of a promise using the &lt;a href="https://miro.medium.com/max/1210/1*0wJYjMQ9uwVEYzBj89oL4A.gif" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;new&lt;/em&gt;&lt;/strong&gt; keyword&lt;/a&gt; with the promise constructor function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F1%2AtMeVXaUM_CHpZ3sXGlFzuA.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AtMeVXaUM_CHpZ3sXGlFzuA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to fulfill or reject the promise?
&lt;/h2&gt;

&lt;p&gt;The promise constructor function accepts one function as its argument — let us pass in an arrow function (but we could just as easily use a function expression).&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ACC3LeEpSGKhndrshT50t8w.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ACC3LeEpSGKhndrshT50t8w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This function is called an executor function, it automatically receives two arguments &lt;code&gt;resolve&lt;/code&gt; and &lt;code&gt;reject&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1000%2F1%2Av4oUtqmnkQltn1XWPe0Atw.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2Av4oUtqmnkQltn1XWPe0Atw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep in mind — &lt;strong&gt;&lt;em&gt;resolve&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;reject&lt;/em&gt;&lt;/strong&gt; both are functions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;resolve&lt;/code&gt; is a function which when called changes the status of the promise from pending to fulfilled.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;reject&lt;/code&gt; is a function which when called changes the status of the promise from pending to rejected&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to keep in mind you cannot directly mutate the status of a promise — you can call the &lt;strong&gt;&lt;em&gt;resolve&lt;/em&gt;&lt;/strong&gt; function to fulfill the promise or the &lt;strong&gt;&lt;em&gt;reject&lt;/em&gt;&lt;/strong&gt; function to reject the 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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AAOOd5xCR_LgcMIiuBPgSrw.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AAOOd5xCR_LgcMIiuBPgSrw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both these functions are typically called after an async operation.&lt;/p&gt;

&lt;p&gt;To keep things simple, let’s use &lt;code&gt;setTimeout()&lt;/code&gt; to simulate the time it takes to search for the Tofu. We’ll assume that it takes your pal five minutes to go out and text you back.&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%2Fmiro.medium.com%2Fmax%2F1280%2F1%2Aqf1pLyDTJvlhTqgJqoPx-g.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%2Fmiro.medium.com%2Fmax%2F1280%2F1%2Aqf1pLyDTJvlhTqgJqoPx-g.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%2Fmiro.medium.com%2Fmax%2F1296%2F1%2AhcCPqO_opLOi3o0dGLJMBA.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%2Fmiro.medium.com%2Fmax%2F1296%2F1%2AhcCPqO_opLOi3o0dGLJMBA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We refactored our code to include the &lt;code&gt;setTimeout&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;If we get the Tofu — we will call &lt;code&gt;resolve&lt;/code&gt; after five minutes, if we can not get the Tofu — we call &lt;code&gt;reject&lt;/code&gt; after five minutes.&lt;/p&gt;

&lt;p&gt;This is pretty much how you fulfill or reject a promise.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to Run a Callback Function — Depending on Whether the Promise Is &lt;em&gt;Resolved&lt;/em&gt; or &lt;em&gt;Rejected&lt;/em&gt;.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The final step is to understand how to execute callback functions based on a promise’s state change. Remember that callback functions are functions that are supplied as an argument to another function.&lt;/p&gt;

&lt;p&gt;Callback function means that we will use that function as an argument to another function.&lt;/p&gt;

&lt;p&gt;Let us define two callback functions — &lt;code&gt;onFulfilled&lt;/code&gt; and &lt;code&gt;onFailure&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F1%2A_sWxMGiP9K-fxqAdKdX4IA.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A_sWxMGiP9K-fxqAdKdX4IA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;onFulfilled()&lt;/code&gt; is the function to be called if &lt;strong&gt;&lt;em&gt;resolve&lt;/em&gt;&lt;/strong&gt; is called after the async operation&lt;/p&gt;

&lt;p&gt;&lt;code&gt;onFailure()&lt;/code&gt;is the function to be called if &lt;strong&gt;&lt;em&gt;reject&lt;/em&gt;&lt;/strong&gt; is called after the async operation.&lt;/p&gt;

&lt;p&gt;Ideally, there would be more code in your callback functions but we simply log into the console and it serves the purpose.&lt;/p&gt;

&lt;p&gt;Going back to our analogy, if we found the Tofu then our promise is fulfilled — we want to set up the table to eat. If the couldn’t find the Tofu then our promise is rejected — we have to start cooking the pasta.&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%2Fmiro.medium.com%2Fmax%2F6912%2F1%2AzAiwSKlhwltUZeP5xZvAGA.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%2Fmiro.medium.com%2Fmax%2F6912%2F1%2AzAiwSKlhwltUZeP5xZvAGA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may be wondering how to make use of these two callback functions?&lt;/p&gt;

&lt;p&gt;When we create a new promise using the promise constructor function the promise object gives us access to two methods — &lt;code&gt;then()&lt;/code&gt; and &lt;code&gt;catch()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can call it using &lt;code&gt;promise.then()&lt;/code&gt; and &lt;code&gt;promise.catch()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The important bit here is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  If the status of the promise changes from pending to fulfilled by calling the &lt;code&gt;resolve&lt;/code&gt; function — the function that is passed to &lt;code&gt;then()&lt;/code&gt; function will automatically get invoked&lt;/li&gt;
&lt;li&gt;  If the status of the promise changes from pending to rejected by calling the &lt;code&gt;reject&lt;/code&gt; function the function that is passed to &lt;code&gt;catch()&lt;/code&gt; function will automatically get invoked&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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2A8KP6GnrNBaeq1bZpJLW2jw.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2A8KP6GnrNBaeq1bZpJLW2jw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our case, we need to pass&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;onFulfilled&lt;/code&gt; function to &lt;code&gt;then()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;onFailure&lt;/code&gt; function to &lt;code&gt;catch()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both functions are callback functions since they are supplied as arguments to other functions. I’m reminding you of this repeatedly since I’ve seen many individuals get afraid of the term “callback” — there is nothing to fear — they are just regular functions.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AwusFSG_8gbm0dxNUYUTy8g.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AwusFSG_8gbm0dxNUYUTy8g.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AfXY1VLoLsNwaRqfXsIsVpA.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AfXY1VLoLsNwaRqfXsIsVpA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our promise code works as expected. But there is room for improvement!&lt;/p&gt;

&lt;p&gt;What if we want to send out some data when &lt;strong&gt;&lt;em&gt;resolving&lt;/em&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;em&gt;rejecting&lt;/em&gt;&lt;/strong&gt; a promise?&lt;/p&gt;

&lt;p&gt;That way inside our callback functions we can make use of the value to do something else.&lt;/p&gt;

&lt;p&gt;Well, it turns out that we can do that by passing an argument to &lt;strong&gt;&lt;em&gt;resolve&lt;/em&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;em&gt;reject&lt;/em&gt;&lt;/strong&gt;,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  for the &lt;strong&gt;&lt;em&gt;resolve&lt;/em&gt;&lt;/strong&gt; function, we’ll pass in a string that says &lt;code&gt;Got the Tofu&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  for &lt;strong&gt;&lt;em&gt;reject&lt;/em&gt;&lt;/strong&gt; function, we will pass in a string that says &lt;code&gt;Can’t get Tofu&lt;/code&gt;
&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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AXYWSjSOSmiy4XuXfkeFHHA.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2AXYWSjSOSmiy4XuXfkeFHHA.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2A6RorBrRM7TdjsBEcZTP9rw.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%2Fmiro.medium.com%2Fmax%2F1000%2F1%2A6RorBrRM7TdjsBEcZTP9rw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But how do we access these strings in our callback function?&lt;/p&gt;

&lt;p&gt;Well, the great thing about a promise is that it will automatically inject the argument passed to &lt;em&gt;resolve&lt;/em&gt; as the argument to the &lt;code&gt;onFulfilled&lt;/code&gt; callback and the argument passed to &lt;strong&gt;&lt;em&gt;reject&lt;/em&gt;&lt;/strong&gt; as the argument to the &lt;code&gt;onFailure&lt;/code&gt; callback.&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%2Fmiro.medium.com%2Fmax%2F1504%2F1%2AihtxdnipaHUONsLsjc0gyg.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%2Fmiro.medium.com%2Fmax%2F1504%2F1%2AihtxdnipaHUONsLsjc0gyg.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%2Fmiro.medium.com%2Fmax%2F1297%2F1%2A-s9oryvwxOitqLr-pl3lCA.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%2Fmiro.medium.com%2Fmax%2F1297%2F1%2A-s9oryvwxOitqLr-pl3lCA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see that I’ve included parameters to both these callbacks and simply log them to the console.&lt;/p&gt;

&lt;p&gt;We would now see the output &lt;code&gt;Got the Tofu Set up the table&lt;/code&gt; when the promise is fulfilled or if there is an error and hence a rejection we would see &lt;code&gt;Can't get Tofu Cook pasta.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2000%2F1%2AhiCMDWkdyM8C12p_YvVJhw.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%2Fmiro.medium.com%2Fmax%2F2000%2F1%2AhiCMDWkdyM8C12p_YvVJhw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One great example of using promises is fetching data from a server; we promise that we’ll eventually get the data, but there’s always a chance that problems will occur.&lt;/p&gt;

&lt;p&gt;In a practical scenario, things will be different.&lt;/p&gt;

&lt;p&gt;Your result would be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  an object(JSON)&lt;/li&gt;
&lt;li&gt;  an array,&lt;/li&gt;
&lt;li&gt;  or any other data type that your async operation returns.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Essentially this is pretty much is the fundamentals of promises in JavaScript. There are a few more details which we will understand in the next article.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“A promise means everything, but once it gets broken, sorry means nothing”&lt;/p&gt;

&lt;p&gt;— anonymous&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  A promise is an object — a &lt;strong&gt;placeholder&lt;/strong&gt; for the eventual result.&lt;/li&gt;
&lt;li&gt;  In past we used Callbacks, to perform the async operation&lt;/li&gt;
&lt;li&gt;  Using callback was a pain especially when you needed to do error handling.&lt;/li&gt;
&lt;li&gt;  Promises standardized the way to deal with asynchronous events and Callbacks.&lt;/li&gt;
&lt;li&gt;  A promise is always in one of three states: pending (the first), fulfilled, or rejected.&lt;/li&gt;
&lt;li&gt;  The operation was completed was marked as fulfilled. The operation was rejected, which means it failed.&lt;/li&gt;
&lt;li&gt;  We create a promise using the &lt;a href="https://miro.medium.com/max/1210/1*0wJYjMQ9uwVEYzBj89oL4A.gif" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;new&lt;/em&gt;&lt;/strong&gt; keyword&lt;/a&gt; with the promise constructor function.&lt;/li&gt;
&lt;li&gt;  You cannot directly mutate the status of a promise — you can call the &lt;strong&gt;&lt;em&gt;resolve&lt;/em&gt;&lt;/strong&gt; function to fulfill the promise or the &lt;strong&gt;&lt;em&gt;reject&lt;/em&gt;&lt;/strong&gt; function to reject the promise.&lt;/li&gt;
&lt;li&gt;  We learned How a Promise is created, How to Fulfil or Reject a Promise, How to Run a Callback Function — Depending on Whether the Promise Is Resolved or Rejected.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Note of Gratitude
&lt;/h1&gt;

&lt;p&gt;I wanted to take this last opportunity to say thank you.&lt;/p&gt;

&lt;p&gt;Thank you for being here! I would not be able to do what I do withoutpeople like youwho follow along and take that leap of faith to read my post.&lt;/p&gt;

&lt;p&gt;I hope you’ll &lt;a href="https://polymathsomnath.medium.com/subscribe" rel="noopener noreferrer"&gt;&lt;strong&gt;join me&lt;/strong&gt;&lt;/a&gt; in &lt;a href="https://polymathsomnath.medium.com/subscribe" rel="noopener noreferrer"&gt;&lt;strong&gt;my future blog post&lt;/strong&gt;&lt;/a&gt; and stick around because I think we have something great here. And I hope that I will be able to help you along in your career for many more years to come!&lt;/p&gt;

&lt;p&gt;See you next time. Bye!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Secret of Great Programmers Revealed</title>
      <dc:creator>Somnath Singh</dc:creator>
      <pubDate>Mon, 06 Dec 2021 08:23:07 +0000</pubDate>
      <link>https://dev.to/polymathsomnath/secret-of-great-programmers-revealed-4f5j</link>
      <guid>https://dev.to/polymathsomnath/secret-of-great-programmers-revealed-4f5j</guid>
      <description>&lt;p&gt;A human being is always longing to be something more than what he is right now. This desire to be something more pushes humans to greatness.&lt;/p&gt;

&lt;p&gt;One sure way you can achieve greatness in any field is through &lt;strong&gt;&lt;em&gt;deliberate practice.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you don’t practice deliberately, you’re wasting your time.&lt;/p&gt;

&lt;p&gt;As to popular notion, deliberate practice is not performing a task again and again.&lt;/p&gt;

&lt;p&gt;For example, if you ask yourself, “&lt;strong&gt;Why&lt;/strong&gt; am I &lt;strong&gt;performing&lt;/strong&gt; this task?” and your answer is, “to complete the task,” then you’re not doing deliberate practice.&lt;/p&gt;

&lt;h1&gt;
  
  
  You need to do the right things — if you want the right things to happen to you
&lt;/h1&gt;

&lt;p&gt;Yes, deliberate practice means repetition, but repetition doesn’t mean doing the same thing mindlessly. It means performing the task to increase your mastery of one or more aspects of the task.&lt;/p&gt;

&lt;p&gt;You do deliberate practice to improve your ability to perform a task. It’s about acquiring the skill with the correct technique.&lt;/p&gt;

&lt;p&gt;It means doing the repetition while giving all your attention . Doing the task over and over again, until you achieve your desired level of mastery.&lt;/p&gt;

&lt;p&gt;The only one who devotes himself to a cause with his whole strength and soul can be a true master.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For this reason, mastery demands all of a person.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;— Albert Einstein&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;You do deliberate practice to master the task, not to complete the task.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The main aim of professional development is to finish a product. Where as the main aim of deliberate practice is to improve your performance — both are not the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ask yourself:
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;How much of your time do you spend developing someone else’s product? And how much developing yourself?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Let me know your answers in the comments section.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  If you show me the HOW — I will find the WHY
&lt;/h1&gt;

&lt;p&gt;Peter Norvig has written the most popular book ever on Artificial Intelligence.&lt;/p&gt;

&lt;p&gt;In his famous post, &lt;a href="http://in%20his%20popular%20post%2C%20teach%20yourself%20programming%20in%20ten%20years%2C/"&gt;&lt;em&gt;Teach Yourself Programming in Ten Years&lt;/em&gt;&lt;/a&gt;, he says that “it may be that 10,000 hours…is the magic number.”&lt;/p&gt;

&lt;p&gt;I remember reading this article by &lt;a href="https://en.wikipedia.org/wiki/Peter_Norvig"&gt;Peter Norvig&lt;/a&gt; in my teens and thinking this must be a joke! After all, who can spend that much time? No, this isn’t a joke.&lt;/p&gt;

&lt;p&gt;There is no substitute for personal experience — once you have it, &lt;em&gt;you know it&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Peter Norvig explains:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The key to developing expertise is deliberate practice: not just doing it again and again, but challenging yourself with a task that is just beyond your current ability, trying it, analyzing your performance while and after doing it, and correcting any mistakes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is little point in practicing something you are already good at. &lt;strong&gt;Deliberate practice means practicing something you are not good at.&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Quantity Leads To Quality
&lt;/h1&gt;

&lt;p&gt;As David Bayles and Ted Orland write in &lt;a href="http://www.amazon.ca/Art-Fear-Observations-Rewards-Artmaking/dp/0961454733"&gt;&lt;em&gt;Art and Fear&lt;/em&gt;&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The ceramics teacher announced on opening day that he was dividing the class into two groups. Students on the left side of the studio would be rated on quantity, while students on the right would be graded on quality.&lt;/p&gt;

&lt;p&gt;His procedure was simple:&lt;/p&gt;

&lt;p&gt;On the final day of class, he would bring in his bathroom scales and weigh the work of the “quantity” group: fifty pounds of pots rated an “A”, forty pounds a “B”, and so on.&lt;/p&gt;

&lt;p&gt;However, those graded on “&lt;strong&gt;quality&lt;/strong&gt;” needed to produce only one pot — albeit a perfect one — to get an “A”.&lt;/p&gt;

&lt;p&gt;Well, came grading time and a curious fact emerged: the group graded for quantity produced the highest quality works.&lt;/p&gt;

&lt;p&gt;It seems that while the “quantity” group was busily churning out piles of work — and learning from their mistakes.&lt;/p&gt;

&lt;p&gt;The “quality” group had sat theorizing about perfection, and in the end, had little more to show for their efforts than grandiose theories and a pile of dead clay.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  TAKEAWAY:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Don’t get too hung up initially on polishing your work to &lt;strong&gt;perfection&lt;/strong&gt;. Instead, focus on cranking out as much as you can.&lt;/li&gt;
&lt;li&gt;  Doing something will lead to doing it well.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Never give up — great things take time
&lt;/h1&gt;

&lt;p&gt;When you first learn to program, you are forced to practice purposefully. Since everything is new and challenging — you put in the hard work.&lt;/p&gt;

&lt;p&gt;But this phase fades and motivation to study tough new topics also fades away.&lt;/p&gt;

&lt;p&gt;Once we achieve a certain skill level (like getting a good job), it’s easy to stop pushing ourselves, settle for the daily grind, and shun all challenges.&lt;/p&gt;

&lt;p&gt;Take Shinji for example, he is considered the &lt;a href="http://www.swimwellblog.com/archives/1663/"&gt;“most graceful” swimmer in the world&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;He started frequently swimming in his late 30s, and now his swimming video on YouTube is more popular than Michael Phelps’.&lt;/p&gt;

&lt;p&gt;How did an average guy with a job and a family get so good?&lt;/p&gt;

&lt;p&gt;He practiced a &lt;a href="http://www.swimwellblog.com/archives/1666/"&gt;&lt;em&gt;lot.&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I made it my goal to become the ‘most graceful swimmer in the world.’&lt;/p&gt;

&lt;p&gt;Whenever I was in Japan, I spent 3 to 4 hours in the endless pool, usually from 10PM to 2AM, four days a week, recording my swim, analyzing it frame by frame, finding and fixing small flaws, one by one.” -Shinji&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is an excellent example of &lt;strong&gt;deliberate&lt;/strong&gt; &lt;strong&gt;practice.&lt;/strong&gt; You work hard, push yourself to your limits, and keep going until you progress and move up a level.&lt;/p&gt;

&lt;p&gt;If something feels uncomfortable it means you are pushing your limits — Do it until you get &lt;em&gt;comfortable —&lt;/em&gt; &lt;strong&gt;Embrace&lt;/strong&gt; it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Mile by mile one hits the milestone
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;No matter how great the talent or efforts, some things just take time. You can’t produce a baby in one month by getting nine women pregnant.&lt;/p&gt;

&lt;p&gt;— Warren Buffet&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Mary Poppendieck&lt;/strong&gt; has co-created lean software.&lt;/p&gt;

&lt;p&gt;She’s also co-authored award-winning books.&lt;/p&gt;

&lt;p&gt;In the book &lt;em&gt;Leading Lean Software Developmen_t, Mary Poppendieck notes that &lt;strong&gt;“&lt;/strong&gt;_it takes elite performers a minimum of 10,000 hours of deliberate, focused practice to become experts.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The expertise arrives gradually over time — not all at once in the 10,000th hour!&lt;/p&gt;

&lt;h2&gt;
  
  
  How to do it:
&lt;/h2&gt;

&lt;p&gt;Nevertheless, 10,000 hours is a lot: about 20 hours per week for 10 years.&lt;/p&gt;

&lt;p&gt;Given this level of commitment, you might be worrying that you’re just not expert material.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You are&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Greatness is essentially a matter of conscious choice — y_our choice._&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Every artist was first an amateur.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;— Ralph Waldo Emerson&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  You don’t have to see the whole staircase — just take the first step
&lt;/h1&gt;

&lt;p&gt;Over the last two decades, research has proven that deliberate practice is most critical factor in building a skill — not ones innate talent.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There is broad consensus among researchers of expert performance that inborn talent does not account for much more than a threshold. You have to have a minimum amount of natural ability to get started in a sport or profession. After that, &lt;strong&gt;the people who excel are the ones who work the hardest.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Deliberate practice does not mean doing what you are good at. It means challenging yourself, doing what you are not good at. So it’s not necessarily fun.&lt;/p&gt;

&lt;p&gt;A kid may move his body a lot, but that does not make him a martial artist.&lt;/p&gt;

&lt;p&gt;This is just like this: you have to do it consciously and increase your difficulty every time.&lt;/p&gt;

&lt;p&gt;That doesn’t mean programming has to feel uncomfortable all the time, but it should regularly confront you with some difficulties.&lt;/p&gt;

&lt;p&gt;Deliberate practice is about learning — learning that changes you, learning that changes who you are.&lt;/p&gt;

&lt;p&gt;Also, it is essential to remember that learning is never created equally. There is a world of difference in what you learn by working alone and working among a group of people.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is a rough road that leads to the path of greatness.&lt;/p&gt;

&lt;p&gt;— Seneca&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How to do it:
&lt;/h2&gt;

&lt;p&gt;When you are building something, don’t do it just for the sake of doing it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Before you begin your coding session, have a &lt;strong&gt;clear goal&lt;/strong&gt; in your mind &lt;strong&gt;what&lt;/strong&gt; you want to achieve through your coding session.&lt;/li&gt;
&lt;li&gt;  Don’t get stuck trying to &lt;strong&gt;get it right&lt;/strong&gt; the first time. Instead, start making one or two things everyday.&lt;/li&gt;
&lt;li&gt;  Check where are you before doing something and where are you after doing it — is there an &lt;strong&gt;&lt;em&gt;improvement&lt;/em&gt;&lt;/strong&gt;? If not, then &lt;strong&gt;why&lt;/strong&gt; — if yes, then &lt;strong&gt;what&lt;/strong&gt;?&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Make an account&lt;/strong&gt; &lt;em&gt;of your progress&lt;/em&gt;.[Important]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In any reasonable application, you probably have a lot of really easy stuff. Things like variable assignments, function definitions, or setting up the databases.&lt;/p&gt;

&lt;p&gt;Maybe for you, the edge of your abilities is on more complex algorithms, data structures or mathematical equations.&lt;/p&gt;

&lt;p&gt;However, if you approach practice blindly, you’ll probably spend 90% of your time on the basics with only 10% of your time on the really difficult stuff that pushes you.&lt;/p&gt;

&lt;p&gt;So for every hour you spend practicing, you’re only really improving for &lt;strong&gt;six minutes&lt;/strong&gt; of that time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The solution here is to craft projects, problems, or practice sessions which deliberately eliminate the easy stuff.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Deliberate Practice your programming problem in such a way that it deliberately forces you to learn the new data structure or algorithm.&lt;/p&gt;

&lt;h1&gt;
  
  
  10,000 Rule Is a Myth
&lt;/h1&gt;

&lt;p&gt;There are a lot of people who say that the 10,000 rule is a myth.&lt;/p&gt;

&lt;p&gt;Some people spend thousands of hours learning and executing a craft and stay mediocre, while others become experts in their field with the same time investment&lt;/p&gt;

&lt;p&gt;As we already discussed, Deliberate practice is not how much time you spend doing something — It is about how you do it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When you are on the path of mastery:&lt;/p&gt;

&lt;p&gt;Conscious Repetition &amp;gt; Inattentive Repetition.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;10,000 figure is a close number where one achieves mastery over something, but it isn’t absolute.&lt;/p&gt;

&lt;p&gt;If one has a razor-sharp focus, what others do in 10 years; he can do it in 4–5 years or even less.&lt;/p&gt;

&lt;h1&gt;
  
  
  Note of Gratitude
&lt;/h1&gt;

&lt;p&gt;I wanted to take this last opportunity to say thank you.&lt;/p&gt;

&lt;p&gt;Thank you for being here! I would not be able to do what I do without people like you who follow along and take that leap of faith to read my post.&lt;/p&gt;

&lt;p&gt;I hope you’ll &lt;a href="https://polymathsomnath.medium.com/subscribe"&gt;&lt;strong&gt;join me&lt;/strong&gt;&lt;/a&gt; in &lt;a href="https://polymathsomnath.medium.com/subscribe"&gt;&lt;strong&gt;my future blog post&lt;/strong&gt;&lt;/a&gt; and stick around because I think we have something great here. And I hope that I will be able to help you along in your career for many more years to come!&lt;/p&gt;

&lt;p&gt;See you next time. Bye!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Git Commands That Will Save Your Job </title>
      <dc:creator>Somnath Singh</dc:creator>
      <pubDate>Thu, 02 Dec 2021 12:59:01 +0000</pubDate>
      <link>https://dev.to/polymathsomnath/git-commands-that-will-save-your-job-14ac</link>
      <guid>https://dev.to/polymathsomnath/git-commands-that-will-save-your-job-14ac</guid>
      <description>&lt;p&gt;In this article, we are going to learn some life-saving Git commands.&lt;/p&gt;

&lt;p&gt;We will not only learn about them, but we will also construct a mental model by understanding how they work behind the scenes.&lt;/p&gt;

&lt;p&gt;Some of these you may have used before, while others may be new to you, but they are all lifesavers.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Real Fault Is to Have Faults And Not to AMEND Them
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;“You will be remembered in your typos and edit history”&lt;/p&gt;

&lt;p&gt;— Anonymous&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Typos happen all the time!&lt;/p&gt;

&lt;p&gt;Git gives us the option to correct our mistakes.&lt;/p&gt;

&lt;p&gt;When committing, sometimes we can hit “Enter” too quickly and have a typo somewhere in the commit message.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AItfh8uj_l0LAbGH9Q9W2bg.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AItfh8uj_l0LAbGH9Q9W2bg.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AfX6dZBNM2d_etdA6-UaITQ.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AfX6dZBNM2d_etdA6-UaITQ.png"&gt;&lt;/a&gt;&lt;/p&gt;
use -amend command to fix the typo





&lt;p&gt;Perfect! Now, your co-workers will not see that your “&lt;strong&gt;commit&lt;/strong&gt;” was originally spelled “&lt;strong&gt;committ&lt;/strong&gt;”.&lt;/p&gt;

&lt;h1&gt;
  
  
  Well Crafted Thing Is a Thing to Behold
&lt;/h1&gt;

&lt;p&gt;You might have used the command &lt;code&gt;git add &amp;lt;file&amp;gt;&lt;/code&gt; or &lt;code&gt;git add .&lt;/code&gt; many times but doing so doesn’t allow us to commit just a section of a file.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AgSwWWmLhWgzttSPlHcTJ7g.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AgSwWWmLhWgzttSPlHcTJ7g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add -p&lt;/code&gt; allows you to stage parts of a changed file, instead of the entire file.&lt;/p&gt;

&lt;p&gt;This allows you to make concise, well-crafted commits that make for an easier-to-read history.&lt;/p&gt;

&lt;p&gt;Doing so can improve the quality of the commits.&lt;/p&gt;

&lt;p&gt;It also makes it easy to remove parts of the changes in a file that was only there for debugging purposes — before the commit without having to go back to the editor.&lt;/p&gt;

&lt;p&gt;Once this command runs, we’ll be asked about “hunks”.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A3SLl1UnyheC5E_m0QXB0mQ.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A3SLl1UnyheC5E_m0QXB0mQ.png"&gt;&lt;/a&gt;&lt;/p&gt;
“Hunks” are the _chunks_ of code that we’ll decide what to do with.





&lt;p&gt;You’ll see the question, “Stage this hunk [y, n, g, a, d, e, ?]?” at the bottom of the terminal.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ASj4F5okGIW-K60QjbRoHNg.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ASj4F5okGIW-K60QjbRoHNg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When finished with all the “hunks”, we will be able to see that our commit is ready and we can continue to the push!&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus Tip:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git commit -p&lt;/code&gt; combines &lt;code&gt;git add -p&lt;/code&gt; and &lt;code&gt;git commit&lt;/code&gt; in one command.&lt;/p&gt;

&lt;h1&gt;
  
  
  Your Mistakes Don’t Define You
&lt;/h1&gt;

&lt;p&gt;You made a commit but now you regret it? Maybe you committed secrets by accident — not a good idea — or maybe you want to add more tests to your code changes.&lt;/p&gt;

&lt;p&gt;These are all legit reasons to undo your last commit.&lt;/p&gt;

&lt;p&gt;Git gives us a command to undo our last commit.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A1KBq39Wsd0HJWO4v0q8WNQ.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A1KBq39Wsd0HJWO4v0q8WNQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command &lt;code&gt;git reset&lt;/code&gt; has a variety of things you can trail onto it, let’s talk about the "soft" trailing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git reset —soft HEAD~&lt;/code&gt; &lt;em&gt;removes the commit from the current branch, but keep the changes!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The cool thing about this command is that the changes won’t disappear&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;All the changes will stay in the working tree!&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%2Fmiro.medium.com%2Fmax%2F700%2F0%2A05owIT6H4P6xfyf2.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F0%2A05owIT6H4P6xfyf2.gif"&gt;&lt;/a&gt;&lt;/p&gt;
We ran the command git reset — soft HEAD~2 — it moved the HEAD to the previous two commits.





&lt;p&gt;If you don’t want to keep the changes that were introduced by certain commits then use &lt;code&gt;git reset —hard HEAD~&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Aue43AYghqHFJHrg5.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F0%2Aue43AYghqHFJHrg5.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Bonus Tip:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The git &lt;a href="https://gist.github.com/eyarz/64770d343b9cab442b257869f497af9e" rel="noopener noreferrer"&gt;pre-commit hook&lt;/a&gt; is a built-in feature that lets you define scripts that will run automatically before each commit. Use it to reduce the need to cancel commits.&lt;/p&gt;

&lt;h1&gt;
  
  
  Look for your choices, pick the best one, then go with it.
&lt;/h1&gt;

&lt;p&gt;Suppose you are working with a team of developers on a medium to large-sized project.&lt;/p&gt;

&lt;p&gt;Another team member proposed some changes, and you want to apply a few of them to your main project, not &lt;em&gt;all&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Since managing the changes between several Git branches can become a complex task, and you don’t want to merge a whole branch into another branch.&lt;/p&gt;

&lt;p&gt;You only need to pick one or two specific commits. To pick some changes into your main project branch from other branches is called cherry-picking.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AnvKsXUB33j-s5zSlHDsNaQ.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AnvKsXUB33j-s5zSlHDsNaQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this command, we can pick a particular branch that has a commit and pull it into another. Let’s walk through this.&lt;/p&gt;

&lt;p&gt;A commit is a snapshot of your git repository at one point in time and each commit cumulatively forms your repo history.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ADrwJLoomyKrBbVQa1OBFog.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ADrwJLoomyKrBbVQa1OBFog.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;cherry-pick&lt;/code&gt; command takes changes from a target commit and places them onto the HEAD of your currently checked-out branch.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AjB7KWUr2iKnMu0EEI73jJA.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AjB7KWUr2iKnMu0EEI73jJA.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, you may either continue working with the changes in your working directory or you may commit the cherry-picked changes immediately.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2Ao2HlQEG1lWkZpRHK9oOHdg.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2Ao2HlQEG1lWkZpRHK9oOHdg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is helpful if you accidentally make a commit to the wrong branch.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2Ar4Rn2Hf9o0CDJ8lBsXGGLQ.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2Ar4Rn2Hf9o0CDJ8lBsXGGLQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With cherry-picking, you can get those changes onto the correct branch without redoing all that work again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F1%2ATQ4V0IN1v9preGrIOLXQwA.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ATQ4V0IN1v9preGrIOLXQwA.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, use &lt;code&gt;cherry-pick&lt;/code&gt; sparingly!&lt;/p&gt;

&lt;p&gt;Overusing &lt;code&gt;cherry-pick&lt;/code&gt; can lead to duplicate commits, and sometimes a merge may be preferred to preserve commit history.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2Alfz_nmKf_TfNAMue4eKO9Q.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2Alfz_nmKf_TfNAMue4eKO9Q.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-Life Scenario:
&lt;/h2&gt;

&lt;p&gt;Let’s say we have a branch &lt;code&gt;76d12&lt;/code&gt; and we have committed all of our changes.&lt;/p&gt;

&lt;p&gt;There’s another branch, we’ll just use &lt;code&gt;master&lt;/code&gt; but this can be any branch, and we want to pull in &lt;code&gt;76d12&lt;/code&gt;’s commit.&lt;/p&gt;

&lt;p&gt;By using the command, &lt;code&gt;git cherry-pick 76d12&lt;/code&gt;we can get that entire commit into another branch.&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%2Fmiro.medium.com%2Fmax%2F700%2F0%2A0uzNtqDd8KiuSCI9.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F0%2A0uzNtqDd8KiuSCI9.gif"&gt;&lt;/a&gt;&lt;/p&gt;
`cherry-pick b`_ring an entire commit from one branch into another._





&lt;h1&gt;
  
  
  Don’t Want All Of It? No Problem — Just Checkout
&lt;/h1&gt;

&lt;p&gt;Want to Pick a specific file from a branch and bring it into the current branch?&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A1qnjBHU7Q6n5ZKJ93xVFxg.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A1qnjBHU7Q6n5ZKJ93xVFxg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Som, I use &lt;code&gt;git checkout&lt;/code&gt; mostly for switching from one branch to another.&lt;/p&gt;

&lt;p&gt;Yes, I know but we can also use it for checking out files and commits.&lt;/p&gt;

&lt;p&gt;It’s like &lt;code&gt;git cherry-pick&lt;/code&gt; but rather than "cherry-picking" an entire commit, we are diving even deeper into a branch and picking just a particular file that we want to be merged.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ApoZDlGmqOwvJSleVGbiN0g.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ApoZDlGmqOwvJSleVGbiN0g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While staying in &lt;code&gt;master&lt;/code&gt; the entire time, we can run the command &lt;code&gt;git checkout Som-test index.js&lt;/code&gt; to grab that particular committed file in that particular branch and bring it over to master to eventually push.&lt;/p&gt;

&lt;p&gt;That’s pretty neat when a particular branch’s changes are many and we’re only looking for one file to test or push.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git checkout&lt;/code&gt; tells Git which branch or commit to apply your new changes.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AyL68gbUi3Yr4jYw3jM3fhg.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AyL68gbUi3Yr4jYw3jM3fhg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A branch is just a pointer to 1 specific commit, and a commit is a snapshot of your repository at a certain point in 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AVF0e86kTT4PIhyTNB_W0vw.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AVF0e86kTT4PIhyTNB_W0vw.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The branch pointer moves along with each new commit you make.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AI8NzBgYrvHoeUTsuAxP8AA.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AI8NzBgYrvHoeUTsuAxP8AA.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to make changes on a branch that you don’t currently have checked out, you first need to checkout the branch.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AnL8uzFZw9GAG0MN0m2vhaQ.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AnL8uzFZw9GAG0MN0m2vhaQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checking out a branch will update your repo’s files to match the snapshot of whichever commit the branch points 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ATziopasHJcCOarYEDN8aGQ.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ATziopasHJcCOarYEDN8aGQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, the branch pointer will follow each new commit that you make on the branch.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AvU_NQyoorJvW5NHXrzr5xw.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AvU_NQyoorJvW5NHXrzr5xw.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s also possible to directly checkout a commit, which will update your repo’s files to match the snapshot of whichever commit you’ve checked out.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ARlHBw8VmAUyELW1U2uRUQg.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2ARlHBw8VmAUyELW1U2uRUQg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Be aware that checking out a commit moves the HEAD pointer to a commit instead of a branch, putting your repo into what is called a “detached head state” where any changes will not be committed to a branch.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2Asjv7VIu4_XGrNBAmInUQ9A.gif" 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%2Fmiro.medium.com%2Fmax%2F700%2F1%2Asjv7VIu4_XGrNBAmInUQ9A.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While git checkout is great for getting to work with branches, it’s also a useful tool for reviewing old commits since it switches the version of your repo to this older snapshot.&lt;/p&gt;

&lt;h1&gt;
  
  
  Someday…But Not Yet, Not Yet
&lt;/h1&gt;

&lt;p&gt;Suppose we have a bunch of changes to a file but need to go back and test something out before we commit and push this or we’re just not ready to commit our changes.&lt;/p&gt;

&lt;p&gt;That’s where &lt;code&gt;git stash&lt;/code&gt; comes into play.&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AHBo3QdLBcH13_5RqQUpolw.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2AHBo3QdLBcH13_5RqQUpolw.png"&gt;&lt;/a&gt;&lt;/p&gt;
Save uncommitted changes and stash them for later. This is useful for when you want to commit and push, but aren’t ready to commit the changes since the last commit.



&lt;p&gt;When we run the command &lt;code&gt;git stash&lt;/code&gt; it takes those saved, uncommitted changes and "stashes" them for later.&lt;/p&gt;

&lt;p&gt;We can then move around different branches, pull changes into master, etc.&lt;/p&gt;

&lt;p&gt;Once we have finished testing or doing whatever we needed to do, we can go back into our branch, run the command &lt;code&gt;git stash pop&lt;/code&gt; and our changes will come back! It’s like we never even left!&lt;/p&gt;

&lt;h1&gt;
  
  
  It Is Time For You To Get Some Help.
&lt;/h1&gt;

&lt;p&gt;There are a plethora of git commands to choose from. And it’s critical that we don’t run commands without knowing what they’ll do to our code.&lt;/p&gt;

&lt;p&gt;If we were to run just &lt;code&gt;git help &amp;lt;command&amp;gt;&lt;/code&gt; then we would get an explanation of the command right there in our terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;Bonus Tip:&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Running the command &lt;code&gt;git help -w &amp;lt;command&amp;gt;&lt;/code&gt; takes us directly to the website that we can read up on all the things with the command in question.&lt;/p&gt;

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

&lt;p&gt;Git is an extremely useful tool. It may be a nightmare if handled incorrectly. I hope these hidden treasures make your Git experience a little more productive.&lt;/p&gt;

&lt;p&gt;What is your go-to Git command? Please let me know in the comments!&lt;/p&gt;

&lt;h1&gt;
  
  
  Note of Gratitude
&lt;/h1&gt;

&lt;p&gt;I wanted to take this last opportunity to say thank you.&lt;/p&gt;

&lt;p&gt;Thank you for being here! I could not be able to do what I do without people like you who follow along and take that leap of faith to read my post.&lt;/p&gt;

&lt;p&gt;I hope you’ll &lt;a href="https://polymathsomnath.medium.com/subscribe" rel="noopener noreferrer"&gt;&lt;strong&gt;join me&lt;/strong&gt;&lt;/a&gt; in &lt;a href="https://polymathsomnath.medium.com/subscribe" rel="noopener noreferrer"&gt;&lt;strong&gt;my future blog post&lt;/strong&gt;&lt;/a&gt; and stick around because we have something great here.&lt;/p&gt;

&lt;p&gt;And I hope I will help you along in your career for many more years to come!&lt;/p&gt;

&lt;p&gt;See you next time. Bye!&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>devops</category>
    </item>
    <item>
      <title>Become Super Productive with Console.X</title>
      <dc:creator>Somnath Singh</dc:creator>
      <pubDate>Sat, 24 Jul 2021 13:11:36 +0000</pubDate>
      <link>https://dev.to/polymathsomnath/become-super-productive-with-console-x-fbe</link>
      <guid>https://dev.to/polymathsomnath/become-super-productive-with-console-x-fbe</guid>
      <description>&lt;p&gt;The better you know the machine, the better you can use it!&lt;/p&gt;

&lt;p&gt;Yes or no?&lt;/p&gt;

&lt;p&gt;Whether you make your living in a blue-collar or white-collar career, you must always have access to the right tools you need to do your job. Otherwise, not only will you not be able to perform in the ways you need to, but you also won’t have as positive a relationship with your work.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“A man is only as good as his tools.”&lt;/p&gt;

&lt;p&gt;― Emmert Wolf&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Developers debugging console has been available in one form or another in web browsers for many years.&lt;/p&gt;

&lt;p&gt;Starting as a means for errors to be reported to the developer, its capabilities have increased in many ways, such as automatically logging information like network requests, network responses, security errors, or warnings.&lt;/p&gt;

&lt;p&gt;There is more to the console object than just &lt;code&gt;console.log()&lt;/code&gt;. Though the console object has got a shedload of features — very few get explored.&lt;/p&gt;

&lt;p&gt;In this article, We will unravel the console object — things that remain hidden for most of the developers.&lt;/p&gt;

&lt;h1&gt;
  
  
  Come, let us sit at the table and have some conversation!
&lt;/h1&gt;

&lt;p&gt;You might have put an array or object inside a &lt;code&gt;console.log()&lt;/code&gt;many times.&lt;br&gt;
But do you know that there’s another option for these data types for a more structured display, which is the &lt;code&gt;console.table()&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AYrG-PQFFE3yncV4XGNMGeQ.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AYrG-PQFFE3yncV4XGNMGeQ.png" alt="console.table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Be patient, the tables will turn.&lt;/p&gt;

&lt;p&gt;(And if they won’t, make them turn.)&lt;/p&gt;

&lt;p&gt;— The Ruhaniyat&lt;/p&gt;
&lt;/blockquote&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%2Fmiro.medium.com%2Fmax%2F1728%2F1%2AK81Qh_p9XcZ3wM1q-zWtww.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%2Fmiro.medium.com%2Fmax%2F1728%2F1%2AK81Qh_p9XcZ3wM1q-zWtww.png" alt="console.table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This looks much slick, isn’t it?&lt;/p&gt;

&lt;h1&gt;
  
  
  Time to add some flavors to your life.
&lt;/h1&gt;

&lt;p&gt;JavaScript gives us are five options to log messages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;console.log( ) | console.info( ) | console.debug( ) | console.warn( ) | console.error( )&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“People try to hold onto the sameness. This holding onto prevents growth.”&lt;/p&gt;

&lt;p&gt;— Bruce Lee&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At first glance they seem to do the same thing and technically, they do! The browsers provide additional features tied to the five commands to give each their own distinct benefit.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2A90dcqR68dQ6CePZxU-reqQ.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2A90dcqR68dQ6CePZxU-reqQ.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AZG2XfQ-4m3OWOHvpkhxSWw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AZG2XfQ-4m3OWOHvpkhxSWw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The intentions for the usage of &lt;strong&gt;&lt;em&gt;error&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;warn&lt;/em&gt;&lt;/strong&gt; are easy to determine — how to use the other choices is up to you.&lt;/p&gt;

&lt;p&gt;Don’t just write better error messages, write code that doesn’t need them.&lt;/p&gt;

&lt;h1&gt;
  
  
  Darling, you need to add some colour to your life.
&lt;/h1&gt;

&lt;p&gt;Wouldn’t it be amazing if the errors come up in red and warnings in yellow?&lt;/p&gt;

&lt;p&gt;Is it possible? Definitely!&lt;/p&gt;

&lt;p&gt;You can apply CSS styles to the console’s output. It works just like the string substitution method where you insert a &lt;code&gt;%c&lt;/code&gt; variable for styles to be applied from the parameters.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AUgWCpjbUrmmG8JEsJD9STw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AUgWCpjbUrmmG8JEsJD9STw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the %c before the I in the above statement.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AXyE8DWFrVA2gWcM-PBTJ2Q.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AXyE8DWFrVA2gWcM-PBTJ2Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Colour to the eye what music is to the ear.”&lt;/p&gt;

&lt;p&gt;— Louis Comfort Tiffany&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is just a sample, you can achieve a lot of things using CSS. If you are interested then, &lt;a href="https://stackoverflow.com/questions/7505623/colors-in-javascript-console#:~:text=Use%20Markdown%20for%20log%20messages.&amp;amp;text=The%20CSS%20format%20specifier%20allows,apply%20as%20the%20second%20parameter." rel="noopener noreferrer"&gt;have a look at this thread.&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Memories of a past love — C Programming.
&lt;/h1&gt;

&lt;p&gt;In C programming there is something called &lt;strong&gt;placeholders&lt;/strong&gt;. These placeholders are also called &lt;strong&gt;format specifiers&lt;/strong&gt;. It determines the &lt;strong&gt;format&lt;/strong&gt; of the input and output.&lt;/p&gt;

&lt;p&gt;Not many know this but JavaScript also provides us placeholders. We can make use of those placeholders in JavaScript’s &lt;code&gt;console.log()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AYa1-cyt8ZInp--Hm4rTQmw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AYa1-cyt8ZInp--Hm4rTQmw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2A-xQhpR_ZFPTwU4c8-PQwYA.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2A-xQhpR_ZFPTwU4c8-PQwYA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the %s and %o that we have used in the console.log()&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AkvnQbW_yMSJHSgqXhJp2fw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AkvnQbW_yMSJHSgqXhJp2fw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Can You Describe that thing a Little Better?
&lt;/h1&gt;

&lt;p&gt;When something is descriptive it gives us a better idea of what that thing possibly would be.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;console&lt;/code&gt;&lt;code&gt;**.**&lt;/code&gt;&lt;code&gt;dir()&lt;/code&gt; displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AmM-cvD0Z8tDpgmymrSwPBg.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AmM-cvD0Z8tDpgmymrSwPBg.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AfuM5ODtr8rkJCwo0MenNIQ.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AfuM5ODtr8rkJCwo0MenNIQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;console.dir() didn’t just give an output but also told what kind it is.&lt;/p&gt;

&lt;p&gt;Things get interesting is when we start using DOM nodes. So let’s look at the difference when we use &lt;code&gt;dir&lt;/code&gt; and &lt;code&gt;log&lt;/code&gt; on &lt;code&gt;document.body&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1210%2F1%2A0X8m1GAoxqPg1lRG5TUhrw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2A0X8m1GAoxqPg1lRG5TUhrw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice, &lt;code&gt;console.log()&lt;/code&gt; prints the element in an HTML-like tree and &lt;code&gt;console.dir()&lt;/code&gt; prints the element in a JSON-like tree.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AQwOf8Fg4KmcVjxKNSyLkxg.gif" 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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AQwOf8Fg4KmcVjxKNSyLkxg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console.log()&lt;/code&gt; gives special treatment to DOM elements, whereas &lt;code&gt;console.dir()&lt;/code&gt; does not. This is often useful when trying to see the full representation of the DOM object.&lt;/p&gt;

&lt;p&gt;In other words, &lt;code&gt;console.dir()&lt;/code&gt; is the way to see all the properties of a specified JavaScript object in the console by which the developer can easily get the properties of the object.&lt;/p&gt;

&lt;h1&gt;
  
  
  Alone we are strong, together we are stronger!
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;group&lt;/strong&gt; is a set of things that are considered because they have something in common. It is quite possible to group the messages with the console.&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;console.group()&lt;/code&gt; we can group different console outputs together to show a form of relationship among 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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AfAkV9c9XdzBwY8LPPpX-pw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AfAkV9c9XdzBwY8LPPpX-pw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We use group. End() to close the group.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AInR_w1a5KdIUL_6qwiMiQg.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AInR_w1a5KdIUL_6qwiMiQg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  You can count on me like 1,2,3 &amp;amp; I’ll be there!
&lt;/h1&gt;

&lt;p&gt;Man, even in the lower stages of development, possesses a faculty which, for want of a better name, I shall call Number Sense. This faculty permits him to recognize that something has changed in a small collection when, without his direct knowledge, an object has been removed from or added to the collection.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Many of the things you can count, don’t count. Many of the things you can’t count, really count.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;— Albert Einstein&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ever wonder how many times a certain thing happens in your code? For instance, how many times does a particular function get called during a sequence of events? That’s where the &lt;code&gt;console.Count()&lt;/code&gt; command can help out.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AhR4lR880a-MvxL2flBd8uA.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AhR4lR880a-MvxL2flBd8uA.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2ARf8khnjIaAVZi6Sj9_TMKA.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2ARf8khnjIaAVZi6Sj9_TMKA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  To know oneself, one should assert oneself.
&lt;/h1&gt;

&lt;p&gt;In life, truth is the only authority. One must reject everything but not the truth.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is truth that liberates, not your effort to be free.&lt;/p&gt;

&lt;p&gt;— J. Krishnamurti&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ever thought of logging something when it is not true?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console.assert()&lt;/code&gt; comes quite handy when you only want to print some selected logs i.e. it will only print the false argument. It does nothing at all if the first argument is true.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2A7uoIfSdG_gI8ALe3ht8Kvw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2A7uoIfSdG_gI8ALe3ht8Kvw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AJSYtY1DH3dLTZx56f0kCtA.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AJSYtY1DH3dLTZx56f0kCtA.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AgA9i-K-D1BH0ddHxYMH1_A.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AgA9i-K-D1BH0ddHxYMH1_A.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Are you tracing it?
&lt;/h1&gt;

&lt;p&gt;Bugs can be a source of frustration. It’s impossible to know straight away which call to the function is creating the bug. Understanding the code execution flow, one can have a better grip on them.&lt;/p&gt;

&lt;p&gt;You can use &lt;code&gt;console.trace()&lt;/code&gt; to get a quick and easy stack trace to better understand code execution flow.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AxRboBdFALSZK88C9fVehew.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AxRboBdFALSZK88C9fVehew.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AU3U1ExVcxSWPlrFVMZCjSA.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AU3U1ExVcxSWPlrFVMZCjSA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In simple terms, &lt;code&gt;console.trace()&lt;/code&gt; will log to the console the call stack that exists at the point &lt;code&gt;console.trace()&lt;/code&gt; was called.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console.trace()&lt;/code&gt; can be very helpful especially, in a large codebase where we have established that the code has a bug in it somewhere but, we aren’t sure exactly where it is.&lt;/p&gt;

&lt;h1&gt;
  
  
  Do you realize that’s the first time you’ve done that?
&lt;/h1&gt;

&lt;p&gt;The &lt;a href="https://javascript.plainenglish.io/the-secrets-surrounding-for-loops-in-javascript-3db58541caa9?source=friends_link&amp;amp;sk=665c05b53d48c8d6316f4fc3df107be1" rel="noopener noreferrer"&gt;majority of code execution time is spent within loops&lt;/a&gt;. Understanding the performance impact of loops in JavaScript is essential in becoming a better developer.&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;console.time()&lt;/code&gt; one can get an idea of how long a certain section of code is taking.&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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AhzuLAyoMO3HpYmo3edbZ-g.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AhzuLAyoMO3HpYmo3edbZ-g.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AsEE4QRBY-ijPXEJc7FKuTw.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%2Fmiro.medium.com%2Fmax%2F1210%2F1%2AsEE4QRBY-ijPXEJc7FKuTw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Time is a created thing. To say ‘I don’t have time’, is like saying, ‘I don’t want to.”&lt;/p&gt;

&lt;p&gt;― &lt;strong&gt;Lao Tzu&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When I covered the &lt;a href="https://javascript.plainenglish.io/the-secrets-surrounding-for-loops-in-javascript-3db58541caa9?source=friends_link&amp;amp;sk=665c05b53d48c8d6316f4fc3df107be1" rel="noopener noreferrer"&gt;performance of loops in an article&lt;/a&gt;, I found that the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance/now" rel="noopener noreferrer"&gt;&lt;strong&gt;Performance Interface&lt;/strong&gt;&lt;/a&gt;  gives more &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance/now" rel="noopener noreferrer"&gt;accurate results&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Learn to see the console object as a multifaceted tool. Each tool is designed precisely for a specific purpose. Choosing the correct tool will decrease the amount of effort required to get a job done. I hope you will choose well.&lt;/p&gt;

&lt;h1&gt;
  
  
  Further Reading
&lt;/h1&gt;

&lt;p&gt;This isn’t &lt;em&gt;everything&lt;/em&gt; possible — there’s simply too much to cover. In some cases, each browser has its capabilities or utilities that can be leveraged. We explored just a few. I invite you to dig deeper to discover more ways to leverage browser DevTools for your coding projects.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/console" rel="noopener noreferrer"&gt;MDN: Console Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://developers.google.com/chrome-developer-tools/docs/console-api" rel="noopener noreferrer"&gt;Google Developers: Console API Reference&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://developers.google.com/chrome-developer-tools/docs/tips-and-tricks" rel="noopener noreferrer"&gt;Google Developers: Dev Tools Tips and Tricks&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;console.table()&lt;/code&gt; gives b*etter visualization of data.*&lt;/li&gt;
&lt;li&gt;  Other than &lt;code&gt;**console.log( )**&lt;/code&gt;  we can have&lt;code&gt;**console.info( )**&lt;/code&gt; &lt;strong&gt;|&lt;/strong&gt; &lt;code&gt;**console.debug( )**&lt;/code&gt; &lt;strong&gt;|&lt;/strong&gt; &lt;code&gt;**console.warn( )**&lt;/code&gt; &lt;strong&gt;|&lt;/strong&gt; &lt;code&gt;**console.error( )**&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  You can insert a &lt;code&gt;%c&lt;/code&gt; variable and use various CSS styling options.&lt;/li&gt;
&lt;li&gt;  We have placeholder in JavaScript like &lt;code&gt;%s&lt;/code&gt; &lt;code&gt;%d&lt;/code&gt; &lt;code&gt;%i&lt;/code&gt; &lt;code&gt;%f&lt;/code&gt; &lt;code&gt;%o&lt;/code&gt; that can determine &lt;strong&gt;format&lt;/strong&gt; of the output.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;console.dir()&lt;/code&gt; prints a JSON representation of the specified object.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;console.group()&lt;/code&gt; can be used for &lt;em&gt;grouping messages&lt;/em&gt; in the console.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;console.count()&lt;/code&gt; logs the number of times that this particular call to &lt;code&gt;count()&lt;/code&gt; has been called. This function takes an optional argument &lt;code&gt;label&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;console.trace()&lt;/code&gt; method displays a trace that show how the code ended up at a certain point.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;console.assert()&lt;/code&gt; prints a statement when it is false.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;console.time()&lt;/code&gt; can be used to track the micro-time taken for JavaScript executions.&lt;/li&gt;
&lt;li&gt;  Learn to see the console object as a multifaceted tool, use the right tool for the job.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Note of Gratitude
&lt;/h1&gt;

&lt;p&gt;I wanted to take this last opportunity to say thank you.&lt;/p&gt;

&lt;p&gt;Thank you for being here! I would not be able to do what I do without  people like you  who follow along and take that leap of faith to read my post.&lt;/p&gt;

&lt;p&gt;I hope you’ll &lt;a href="https://twitter.com/tweetsbysoma" rel="noopener noreferrer"&gt;&lt;strong&gt;join me&lt;/strong&gt;&lt;/a&gt; in &lt;a href="https://xps8zvgfv2x.typeform.com/to/AmZnFhsK" rel="noopener noreferrer"&gt;&lt;strong&gt;my future blog post&lt;/strong&gt;&lt;/a&gt; and stick around because I think we have something great here. And I hope that I can help you along in your career for many more years to come!&lt;/p&gt;

&lt;p&gt;See you next time. Bye!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://xps8zvgfv2x.typeform.com/to/AmZnFhsK" 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%2Fuploads%2Farticles%2Fhdhccyp2ec5iz031qhtu.gif" alt="Newsletter"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Master ‘this’ in JavaScript</title>
      <dc:creator>Somnath Singh</dc:creator>
      <pubDate>Sun, 30 May 2021 06:21:19 +0000</pubDate>
      <link>https://dev.to/polymathsomnath/master-this-in-javascript-1bk</link>
      <guid>https://dev.to/polymathsomnath/master-this-in-javascript-1bk</guid>
      <description>&lt;p&gt;In this article, we cover the all-important yet so confusing topic in JavaScript which is the “&lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt;” keyword.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;If “&lt;em&gt;this&lt;/em&gt;” scares you, do not worry! We will learn how to determine the value of the “&lt;em&gt;this&lt;/em&gt;” keyword using five simple rules.&lt;/p&gt;

&lt;p&gt;Those five simple rules are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;em&gt;The Regular One —&lt;/em&gt; &lt;strong&gt;Default binding&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;em&gt;Function Inside an Object&lt;/em&gt; — &lt;strong&gt;Implicit binding&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;em&gt;Function Borrowing&lt;/em&gt; — &lt;strong&gt;Explicit binding&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;em&gt;Using Function to Create Objects&lt;/em&gt; — &lt;strong&gt;New binding&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;em&gt;How Arrow Function Differs from the Regular Ones—&lt;/em&gt; &lt;strong&gt;Lexical binding&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don’t worry about these scary names. Computer Science people have a fancy for naming terms so that they sound extra-terrestrial. Under the hood, they are just common concepts that any willing human can understand.&lt;/p&gt;

&lt;p&gt;The “&lt;em&gt;this”&lt;/em&gt; variable corresponds to how you invoke a function. These rules help us to determine the value of &lt;em&gt;this&lt;/em&gt; in various scenarios.&lt;/p&gt;

&lt;p&gt;Once you understand these rules, then you would not fear them anymore.&lt;/p&gt;

&lt;p&gt;Before we begin, &lt;a href="https://javascript.plainenglish.io/why-do-developers-fear-this-fb7497f95570?sk=7c1a7d83bd97af7ce9a9cd97fc8abda2" rel="noopener noreferrer"&gt;please go through this article&lt;/a&gt; to understand how &lt;em&gt;this&lt;/em&gt; works.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is “this” in brief
&lt;/h1&gt;

&lt;p&gt;In JavaScript, whenever a function is called, a new execution context is created by the JavaScript engine. That execution context exists until the function has finished executing. Every execution context contains a variable called ‘this’.&lt;/p&gt;

&lt;h1&gt;
  
  
  #Rule 1. Default binding
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2386%2F0%2Axc7asnogg5WscyrC.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%2Fmiro.medium.com%2Fmax%2F2386%2F0%2Axc7asnogg5WscyrC.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When calling a function in a standard way shown above, “&lt;em&gt;this&lt;/em&gt;” will actually refer to the global object!&lt;/p&gt;

&lt;p&gt;In the browser, the global object means the Window object.&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%2Fmiro.medium.com%2Fmax%2F1838%2F0%2ABkSOWChHCrsTt2V5.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%2Fmiro.medium.com%2Fmax%2F1838%2F0%2ABkSOWChHCrsTt2V5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One exception to remember — that is when strict mode is enabled. By writing “use-strict” you can prevent anything from being declared on the global object.&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%2Fmiro.medium.com%2Fmax%2F2160%2F0%2AMDVIyQlMzbnDv4Kf.jpeg" 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%2Fmiro.medium.com%2Fmax%2F2160%2F0%2AMDVIyQlMzbnDv4Kf.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  #Rule 2. &lt;strong&gt;Implicit binding&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;If the function is contained within an object, then that object will be referenced by “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%2Fmiro.medium.com%2Fmax%2F3296%2F1%2AOKrRTgSIiLQ5dJRIyTk-Qg.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%2Fmiro.medium.com%2Fmax%2F3296%2F1%2AOKrRTgSIiLQ5dJRIyTk-Qg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the above, the &lt;code&gt;this&lt;/code&gt; keyword will point to the &lt;code&gt;personObj&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  #Rule 3. &lt;strong&gt;Explicit binding&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;We saw how &lt;code&gt;this&lt;/code&gt; points to the global object and in another case, it points to the object which contains it. Wouldn’t it be nice to able to control what this variable ends up being when the function is called?&lt;/p&gt;

&lt;p&gt;Words like &lt;em&gt;call&lt;/em&gt;, &lt;em&gt;apply&lt;/em&gt;, and &lt;em&gt;bind&lt;/em&gt; usually causes terror in new developers. In reality, they are all functions that can be used to &lt;em&gt;explicitly&lt;/em&gt; set the value of “this”.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let us understand it with an example.
&lt;/h2&gt;

&lt;p&gt;Suppose we have two objects, let us say &lt;code&gt;personObj&lt;/code&gt; and &lt;code&gt;readerObj&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2456%2F1%2At1FOex7gNulGnwVEb6Mf6w.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%2Fmiro.medium.com%2Fmax%2F2456%2F1%2At1FOex7gNulGnwVEb6Mf6w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both the object has a name property. The &lt;code&gt;personObj&lt;/code&gt; has a function that can print the value inside the &lt;code&gt;name&lt;/code&gt; but, the &lt;code&gt;readerObj&lt;/code&gt; does not have any such feature!&lt;/p&gt;

&lt;p&gt;Here we can make use of one of the three methods — &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt; or &lt;code&gt;bind&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This process is called function borrowing.&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%2Fmiro.medium.com%2Fmax%2F1966%2F1%2ADi_MsxdvDTqd0DkEBr3YfQ.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%2Fmiro.medium.com%2Fmax%2F1966%2F1%2ADi_MsxdvDTqd0DkEBr3YfQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We borrowed the &lt;code&gt;sayName&lt;/code&gt; method for the &lt;code&gt;readerObj.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we can print the name property that is in &lt;code&gt;readerObj&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2466%2F1%2AkmRaS-zUJgG_QkrCS-FUIQ.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%2Fmiro.medium.com%2Fmax%2F2466%2F1%2AkmRaS-zUJgG_QkrCS-FUIQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are calling the &lt;code&gt;sayName&lt;/code&gt; method from &lt;code&gt;personObj&lt;/code&gt;, but at the same time, we are instructing the JavaScript engine that the ‘this’ variable in the &lt;code&gt;sayName&lt;/code&gt; method should point to &lt;code&gt;readerObj&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So when the JavaScript engine executes the code, the &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt; variable in the &lt;code&gt;sayName&lt;/code&gt; function does not point to the &lt;code&gt;personObj&lt;/code&gt; but it points to the &lt;code&gt;readerObj&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Does that make sense?&lt;/p&gt;

&lt;p&gt;Not just that — we can also pass some arguments when we use the &lt;code&gt;call&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1860%2F1%2ApQtSBG6fv5pp_L_lfpNKmg.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%2Fmiro.medium.com%2Fmax%2F1860%2F1%2ApQtSBG6fv5pp_L_lfpNKmg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We passed Namaste as an argument&lt;/p&gt;

&lt;p&gt;We can make use of the argument in the &lt;code&gt;sayName&lt;/code&gt; method.&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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AURmM8Vf09inNezYtA2TvMA.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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AURmM8Vf09inNezYtA2TvMA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we execute the code, we will get the output along with the passed argument.&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%2Fmiro.medium.com%2Fmax%2F2956%2F1%2ARcaHst9aMECBaFntGO_9nA.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%2Fmiro.medium.com%2Fmax%2F2956%2F1%2ARcaHst9aMECBaFntGO_9nA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The apply method works the same way, but instead of regular arguments, it takes an array as an argument.&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%2Fmiro.medium.com%2Fmax%2F3416%2F1%2AolLUIkdy373Jhrw3-i3mwg.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%2Fmiro.medium.com%2Fmax%2F3416%2F1%2AolLUIkdy373Jhrw3-i3mwg.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%2Fmiro.medium.com%2Fmax%2F2628%2F1%2AD2IhX_eA_J2F-29dnExflQ.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%2Fmiro.medium.com%2Fmax%2F2628%2F1%2AD2IhX_eA_J2F-29dnExflQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The bind method also works the same way — it can accept a regular argument.&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%2Fmiro.medium.com%2Fmax%2F2328%2F1%2AVvootgY_bLF7xy7k_mKcGg.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%2Fmiro.medium.com%2Fmax%2F2328%2F1%2AVvootgY_bLF7xy7k_mKcGg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But unlike &lt;em&gt;call&lt;/em&gt;  and &lt;em&gt;apply —&lt;/em&gt; &lt;strong&gt;&lt;em&gt;bind&lt;/em&gt;&lt;/strong&gt; returns a function — that function can be stored in a variable and can be executed in the future.&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%2Fmiro.medium.com%2Fmax%2F3350%2F1%2AB7USlXrakqraX9w7ntLtwA.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%2Fmiro.medium.com%2Fmax%2F3350%2F1%2AB7USlXrakqraX9w7ntLtwA.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%2Fmiro.medium.com%2Fmax%2F2604%2F1%2A5kvl7us01wuPUlEpn-KJ3g.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%2Fmiro.medium.com%2Fmax%2F2604%2F1%2A5kvl7us01wuPUlEpn-KJ3g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One can see the use of bind in function currying — a topic that we will cover in the future.&lt;/p&gt;

&lt;h1&gt;
  
  
  #Rule &lt;strong&gt;4. New binding&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;We use the &lt;strong&gt;&lt;em&gt;new&lt;/em&gt;&lt;/strong&gt; keyword to create an instance or copy of an object. What the &lt;strong&gt;new&lt;/strong&gt; keyword does is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  It creates an &lt;strong&gt;empty object&lt;/strong&gt; and then instructs the keyword &lt;strong&gt;this&lt;/strong&gt; to point to that empty object.&lt;/li&gt;
&lt;li&gt;  It then adds a &lt;code&gt;return this&lt;/code&gt; statement to the end of that function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remember, when an instance of an object gets created using the &lt;em&gt;new&lt;/em&gt; keyword, “&lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt;” always points to that newly created instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let us understand this with an example.
&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%2Fmiro.medium.com%2Fmax%2F1702%2F1%2ArdIo3Y77Y054oibfUKFLXg.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%2Fmiro.medium.com%2Fmax%2F1702%2F1%2ArdIo3Y77Y054oibfUKFLXg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we run this code, what are we supposed to 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%2Fmiro.medium.com%2Fmax%2F1960%2F1%2A-0ealF7SmoQwwUbFX3CsGA.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%2Fmiro.medium.com%2Fmax%2F1960%2F1%2A-0ealF7SmoQwwUbFX3CsGA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we said — an empty object!&lt;/p&gt;

&lt;p&gt;What is happening under the hood is&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%2Fmiro.medium.com%2Fmax%2F2240%2F1%2AMjlTUBtzshIO2lToU4b_zQ.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%2Fmiro.medium.com%2Fmax%2F2240%2F1%2AMjlTUBtzshIO2lToU4b_zQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What? Are we invoking the function?&lt;/p&gt;

&lt;p&gt;Yes!&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%2Fmiro.medium.com%2Fmax%2F2556%2F1%2A7jkc1tuK7hNbx25EVcxvLQ.gif" 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%2Fmiro.medium.com%2Fmax%2F2556%2F1%2A7jkc1tuK7hNbx25EVcxvLQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See, I told you it is getting invoked.&lt;/p&gt;

&lt;p&gt;Let us look at the whole thing.&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%2Fmiro.medium.com%2Fmax%2F2240%2F1%2ADw9PlvHl5SXw94wwiFZFTg.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%2Fmiro.medium.com%2Fmax%2F2240%2F1%2ADw9PlvHl5SXw94wwiFZFTg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we put some value in the function, it will put that in the newly created object and then return 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%2Fmiro.medium.com%2Fmax%2F1864%2F1%2AByTa5ihFcU6xzningnM3eg.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%2Fmiro.medium.com%2Fmax%2F1864%2F1%2AByTa5ihFcU6xzningnM3eg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we &lt;code&gt;console.log(newPersonObj)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1768%2F1%2AYeOXSqQdt8Zi8qJmpbQFRg.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%2Fmiro.medium.com%2Fmax%2F1768%2F1%2AYeOXSqQdt8Zi8qJmpbQFRg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us finish this concept with an animation.&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;dev.to&lt;/code&gt; supports animation of 500 frames only, I am attaching  an external link to the animation&lt;br&gt;
&lt;a href="https://miro.medium.com/max/1210/1*0wJYjMQ9uwVEYzBj89oL4A.gif" rel="noopener noreferrer"&gt;Go here for the animation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, we are using a function to create an object.&lt;/p&gt;

&lt;p&gt;This type of function is known as a function constructor.&lt;/p&gt;

&lt;p&gt;Remember, in the &lt;code&gt;newPersonObj&lt;/code&gt;, which stores the copy of &lt;code&gt;personObj&lt;/code&gt;— the “this" variable points to empty &lt;code&gt;personObj&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Does it make sense now?&lt;/p&gt;

&lt;p&gt;Good! Let us now understand the last rule.&lt;/p&gt;

&lt;h1&gt;
  
  
  #Rule &lt;strong&gt;5. Lexical binding&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;With the advent of ES6 — we got arrow functions. Arrow functions with their ultra-lean syntax are a natural replacement for their traditional anonymous counterparts.&lt;/p&gt;

&lt;p&gt;To explicitly invoke an arrow function, as with a regular anonymous function, you would assign it to a variable first:&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%2Fmiro.medium.com%2Fmax%2F2598%2F1%2AMEaHjDB5yTXm_T6tDO_HwA.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%2Fmiro.medium.com%2Fmax%2F2598%2F1%2AMEaHjDB5yTXm_T6tDO_HwA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Arrow functions are just like regular anonymous functions, with one major exception- the behavior of this object inside the function.&lt;/p&gt;

&lt;p&gt;In a regular function, the value of "&lt;code&gt;this&lt;/code&gt;" is context-based- call the function inside a link, and "&lt;code&gt;this&lt;/code&gt;" points to the link's object; call it inside one more function like &lt;code&gt;setInterval()&lt;/code&gt;, then "&lt;code&gt;this&lt;/code&gt;" points to the global window object.&lt;/p&gt;

&lt;p&gt;For example, the following example attempts to call the &lt;code&gt;start()&lt;/code&gt; method of a custom object to increment its counter property by 1 every second, though it fails due to an incorrect assumption of the "&lt;code&gt;this&lt;/code&gt;" object reference counter.&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%2Fmiro.medium.com%2Fmax%2F2976%2F1%2AhoYm0GaVU-9eIG431Vs1wg.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%2Fmiro.medium.com%2Fmax%2F2976%2F1%2AhoYm0GaVU-9eIG431Vs1wg.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%2Fmiro.medium.com%2Fmax%2F1552%2F1%2AJJvXhLyOOGZfSstSj2sS4A.gif" 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%2Fmiro.medium.com%2Fmax%2F1552%2F1%2AJJvXhLyOOGZfSstSj2sS4A.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above, &lt;code&gt;this.counter&lt;/code&gt; fails to properly reference the counter property of the &lt;code&gt;countup&lt;/code&gt; object, though the error may not be so obvious to spot. One can either mistakenly or carelessly assume that "&lt;code&gt;this&lt;/code&gt;" points to the &lt;code&gt;countup&lt;/code&gt; object, when in fact it points to the global &lt;code&gt;window&lt;/code&gt; object due to the context "&lt;code&gt;this&lt;/code&gt;" is being called- inside the global window method &lt;code&gt;setInterval()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The result is a reference to a non-existent &lt;code&gt;window.counter&lt;/code&gt; property that will repeatedly return &lt;code&gt;NaN&lt;/code&gt; when we try to increment it. To properly reference the &lt;code&gt;countup&lt;/code&gt; object then inside the anonymous function, we should cache a reference to the correct "&lt;code&gt;this&lt;/code&gt;" object before the context changes to a different 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%2Fmiro.medium.com%2Fmax%2F2692%2F1%2A_ecuxy27FcjFnlfPRKVZLg.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%2Fmiro.medium.com%2Fmax%2F2692%2F1%2A_ecuxy27FcjFnlfPRKVZLg.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%2Fmiro.medium.com%2Fmax%2F1516%2F1%2AQd4QDX0XnfXBcnkjdQUVgw.gif" 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%2Fmiro.medium.com%2Fmax%2F1516%2F1%2AQd4QDX0XnfXBcnkjdQUVgw.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The "&lt;code&gt;this&lt;/code&gt;" object inside an arrow function is lexically bound, which is just a fancy way of saying its value is static and determined by the place where the “&lt;code&gt;this&lt;/code&gt;" keyword is defined.&lt;/p&gt;

&lt;p&gt;Contrast that with regular functions, where "&lt;code&gt;this&lt;/code&gt;" is dynamic and based on the context it's called regardless of the scope at the time "&lt;code&gt;this&lt;/code&gt;" was defined.&lt;/p&gt;

&lt;p&gt;Let’s take the previous example that gave us trouble initially, and see how changing over to using an arrow function intuitively addresses the problem:&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%2Fmiro.medium.com%2Fmax%2F2804%2F1%2ARxgs1sNx3TXP7cvNe-PsoA.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%2Fmiro.medium.com%2Fmax%2F2804%2F1%2ARxgs1sNx3TXP7cvNe-PsoA.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%2Fmiro.medium.com%2Fmax%2F1516%2F1%2AQd4QDX0XnfXBcnkjdQUVgw.gif" 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%2Fmiro.medium.com%2Fmax%2F1516%2F1%2AQd4QDX0XnfXBcnkjdQUVgw.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We solved the problem by just using an arrow function.&lt;/p&gt;

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

&lt;p&gt;If you understood all the rules, then pat yourself on the back — you deserve it! Now you are no more someone who is afraid of JavaScript’s most confusing concept — the "&lt;em&gt;this&lt;/em&gt;" keyword.&lt;/p&gt;

&lt;p&gt;In this article we learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  When calling a &lt;strong&gt;&lt;em&gt;function&lt;/em&gt;&lt;/strong&gt; in a standard way shown above, “&lt;em&gt;this&lt;/em&gt;” will actually refer to the global object!&lt;/li&gt;
&lt;li&gt;  If the function is contained within an &lt;strong&gt;&lt;em&gt;object,&lt;/em&gt;&lt;/strong&gt; then “&lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt;” will point to that object.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;call&lt;/em&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;em&gt;apply&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;bind&lt;/em&gt;&lt;/strong&gt; are functions that are available to us by JavaScript to alter the behaviour of “&lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt;” in our program.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;new&lt;/em&gt;&lt;/strong&gt; keyword or operator when used makes an empty object, then instructs “&lt;strong&gt;&lt;em&gt;this”&lt;/em&gt;&lt;/strong&gt; to point to that newly created object&lt;/li&gt;
&lt;li&gt;  Arrow function enables us to lexically bind the “&lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt;” keyword in the program, what this means is its value is static and determined by the place where the “&lt;code&gt;this&lt;/code&gt;" keyword is defined.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Note of Gratitude
&lt;/h1&gt;

&lt;p&gt;I wanted to take this last opportunity to say thank you.&lt;/p&gt;

&lt;p&gt;Thank you for being here! I would not be able to do what I do without  people like you  who follow along and take that leap of faith to read my post.&lt;/p&gt;

&lt;p&gt;I hope you’ll &lt;a href="https://twitter.com/tweetsbysoma" rel="noopener noreferrer"&gt;&lt;strong&gt;join me&lt;/strong&gt;&lt;/a&gt; in &lt;a href="https://dev.to/polymathsomnath"&gt;&lt;strong&gt;my future blog post&lt;/strong&gt;&lt;/a&gt; and stick around because I think we have something great here. And I hope that I will be able to help you along in your career for many more years to come!&lt;/p&gt;

&lt;p&gt;See you next time. Bye!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>node</category>
      <category>programming</category>
    </item>
    <item>
      <title>Explain API in Plain English</title>
      <dc:creator>Somnath Singh</dc:creator>
      <pubDate>Mon, 29 Mar 2021 13:01:36 +0000</pubDate>
      <link>https://dev.to/polymathsomnath/explain-api-in-plain-english-54h</link>
      <guid>https://dev.to/polymathsomnath/explain-api-in-plain-english-54h</guid>
      <description>&lt;p&gt;Have you ever heard the word “&lt;strong&gt;API&lt;/strong&gt;,” and wondered exactly what it is? Do you have a vague idea of what it does or what it is used for?&lt;/p&gt;

&lt;p&gt;This is something that you will encounter when you first start programming with any sort of web technology. Many newcomers struggle with this concept, and many get some vague ideas about it and assume that they know what it is.&lt;/p&gt;

&lt;p&gt;Now APIs &lt;a href="https://en.wikipedia.org/wiki/API#Usage" rel="noopener noreferrer"&gt;aren’t exclusive&lt;/a&gt; to web programming but it’s something that you use a lot when you are programming for the web or mobile. In the past, APIs were largely associated with computer operating systems and desktop applications. In recent years though, we have seen the emergence of &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Introduction" rel="noopener noreferrer"&gt;Web APIs&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is an API?
&lt;/h1&gt;

&lt;p&gt;It stands for Application Programming Interface. This sounds scary and fancy at the same time! What does that mean? What exactly is an API?&lt;br&gt;
Like most places, I won’t give you a vague definition, full of technical jargon.&lt;/p&gt;

&lt;p&gt;So, here it is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In a nutshell,&lt;/strong&gt; API is some code that you didn’t write yourself, and that code has some methods that you are allowed to call. It could be something that you download and run from your computer or it could be something that’s someplace else on the web.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;That’s all an API is, in its essence.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don’t think anything else, when we say an API just stick with the definition mentioned above!&lt;/p&gt;

&lt;p&gt;Is that’s all it is? In its essence, Yes.&lt;/p&gt;

&lt;p&gt;Then why such a fancy name?&lt;/p&gt;

&lt;p&gt;Lets find out!&lt;br&gt;
Let us build an API in JavaScript that will enable us to cook our dinner 🍜(virtually ofc).&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%2Fmiro.medium.com%2Fmax%2F2020%2F1%2A6e79uPJ9c-88kgyY-C5wtA.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%2Fmiro.medium.com%2Fmax%2F2020%2F1%2A6e79uPJ9c-88kgyY-C5wtA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our API Code that is stored in the computer&lt;/p&gt;

&lt;p&gt;As I said, we can have APIs that are local on our computer or saved in a &lt;a href="https://en.wikipedia.org/wiki/Web_API" rel="noopener noreferrer"&gt;remote server,&lt;/a&gt; or it could be something that you can download. We have made one locally and named it API, but it can be named anything.&lt;/p&gt;

&lt;p&gt;It is a JavaScript file that I’ve downloaded and saved into a local folder.&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%2Fmiro.medium.com%2Fmax%2F1442%2F1%2A3ItTKyN0anbcRkbogyLmsg.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%2Fmiro.medium.com%2Fmax%2F1442%2F1%2A3ItTKyN0anbcRkbogyLmsg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I run my webpages, I’m able to use this piece 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%2Fmiro.medium.com%2Fmax%2F1348%2F1%2A7k0y7yFKvViPCSKFWuhYcQ.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%2Fmiro.medium.com%2Fmax%2F1348%2F1%2A7k0y7yFKvViPCSKFWuhYcQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is an immediately invoked function expression(IIFE) that is going to run itself.&lt;/p&gt;

&lt;p&gt;At the very bottom, it’s going to return an object, and the object that it’s returning has three properties.&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%2Fmiro.medium.com%2Fmax%2F1336%2F1%2A8H_kVIHNhQPGCn3ZUayJ4Q.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%2Fmiro.medium.com%2Fmax%2F1336%2F1%2A8H_kVIHNhQPGCn3ZUayJ4Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can call these methods using a dot operator.&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%2Fmiro.medium.com%2Fmax%2F1506%2F1%2AyXQh9L_Kqu8XSRYL0RXKhA.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%2Fmiro.medium.com%2Fmax%2F1506%2F1%2AyXQh9L_Kqu8XSRYL0RXKhA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Calling methods described in our API.&lt;/p&gt;

&lt;p&gt;When will call these methods in a row, we get an output like 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%2Fmiro.medium.com%2Fmax%2F2002%2F1%2AeYW0SSF89HBjB7kMhd1KeQ.gif" 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%2Fmiro.medium.com%2Fmax%2F2002%2F1%2AeYW0SSF89HBjB7kMhd1KeQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have function &lt;code&gt;steamVeggies()&lt;/code&gt; that calls other function &lt;code&gt;addSpices()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2398%2F1%2AIdCfU1H1rGetoazetECDVQ.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%2Fmiro.medium.com%2Fmax%2F2398%2F1%2AIdCfU1H1rGetoazetECDVQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here &lt;code&gt;addSpices()&lt;/code&gt; can’t be called directly but I can call &lt;code&gt;steamVeggies()&lt;/code&gt; which will then run the function &lt;code&gt;addSpices()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now what this is doing is just &lt;strong&gt;&lt;em&gt;console logging&lt;/em&gt;&lt;/strong&gt; out some messages, it’s not important what’s being done, what is important is that I have an &lt;strong&gt;object&lt;/strong&gt; with a &lt;strong&gt;name&lt;/strong&gt;. This would be one file that I can download and use, or it could be saved on a remote server, or it could be something that I download and keep with my files, then in my script file, I can use that.&lt;/p&gt;

&lt;p&gt;So, I could say API then dot, and here are the things that were returned from this function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1342%2F1%2AlHPNRX6Ajar52NMeOzzGbw.gif" 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%2Fmiro.medium.com%2Fmax%2F1342%2F1%2AlHPNRX6Ajar52NMeOzzGbw.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  These are the methods that we can call:
&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%2Fmiro.medium.com%2Fmax%2F1348%2F1%2AKKmW90WlJIutHsXQUG7egA.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%2Fmiro.medium.com%2Fmax%2F1348%2F1%2AKKmW90WlJIutHsXQUG7egA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We could say, alright I’m going to call the function &lt;code&gt;step1()&lt;/code&gt; and then I need to call the function &lt;code&gt;step2()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There are other ones in the API like &lt;code&gt;addSpices()&lt;/code&gt; that we can’t call one directly.&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%2Fmiro.medium.com%2Fmax%2F872%2F1%2A9tdmkIDtfAzIgZFoXvi-gQ.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%2Fmiro.medium.com%2Fmax%2F872%2F1%2A9tdmkIDtfAzIgZFoXvi-gQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;calling this one would give us an error&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1264%2F1%2AXiieM9DlGYbZG1lsiwjzXg.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%2Fmiro.medium.com%2Fmax%2F1264%2F1%2AXiieM9DlGYbZG1lsiwjzXg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So there’s code inside there that’s &lt;em&gt;hidden away from us&lt;/em&gt;. We don’t know what it is doing, but some things are &lt;strong&gt;exposed&lt;/strong&gt; to us, which are &lt;strong&gt;&lt;em&gt;public&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;.&lt;/em&gt; We can access those in our code. I can use a &lt;code&gt;step1()&lt;/code&gt;, &lt;code&gt;step2()&lt;/code&gt; and &lt;code&gt;step3()&lt;/code&gt;. These are the things that are available to us from the API.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;A&lt;/strong&gt;pplication &lt;strong&gt;P&lt;/strong&gt;rogramming &lt;strong&gt;I&lt;/strong&gt;nterface, the &lt;strong&gt;Interface&lt;/strong&gt; part of it is these three methods:&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%2Fmiro.medium.com%2Fmax%2F1506%2F1%2AyXQh9L_Kqu8XSRYL0RXKhA.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%2Fmiro.medium.com%2Fmax%2F1506%2F1%2AyXQh9L_Kqu8XSRYL0RXKhA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the &lt;strong&gt;Interface&lt;/strong&gt; part of the code&lt;/p&gt;

&lt;p&gt;Those methods are the interface for me, to interact with this &lt;strong&gt;API&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%2Fmiro.medium.com%2Fmax%2F1348%2F1%2A7k0y7yFKvViPCSKFWuhYcQ.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%2Fmiro.medium.com%2Fmax%2F1348%2F1%2A7k0y7yFKvViPCSKFWuhYcQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is our &lt;strong&gt;Application Programming&lt;/strong&gt; part of the code&lt;/p&gt;

&lt;p&gt;Now, does it make sense why it is called &lt;strong&gt;A&lt;/strong&gt;pplication &lt;strong&gt;P&lt;/strong&gt;rogramming &lt;strong&gt;I&lt;/strong&gt;nterface?&lt;/p&gt;

&lt;p&gt;Now, above we have used the name API, but it doesn’t have to be called &lt;strong&gt;API.&lt;/strong&gt; It could be called anything. You can call it &lt;a href="https://www.twitter.com/tweetsbysoma" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Som&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; if we want.&lt;/p&gt;

&lt;p&gt;What you need to understand is that there is this &lt;a href="https://en.wikipedia.org/wiki/Black_box" rel="noopener noreferrer"&gt;&lt;strong&gt;black box&lt;/strong&gt;&lt;/a&gt; hidden away from us. What we know is from the &lt;a href="https://en.wikipedia.org/wiki/API#Documentation" rel="noopener noreferrer"&gt;&lt;em&gt;documentation&lt;/em&gt;&lt;/a&gt;. It says these are the things that we could use and we use those in our program.&lt;/p&gt;

&lt;p&gt;That’s all an &lt;strong&gt;API&lt;/strong&gt; is. Code that somebody else has written, that I have access to, that I can use in my code to accomplish some sort of task.&lt;/p&gt;

&lt;p&gt;It can be sitting on a &lt;a href="https://en.wikipedia.org/wiki/Web_API" rel="noopener noreferrer"&gt;remote server&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;It can be sitting on my own computer,&lt;/p&gt;

&lt;p&gt;It could be something that I have to use &lt;a href="https://en.wikipedia.org/wiki/Representational_state_transfer" rel="noopener noreferrer"&gt;&lt;strong&gt;HTTP&lt;/strong&gt;&lt;/a&gt; to talk to, I have to make an &lt;a href="https://developers.google.com/web/updates/2015/03/introduction-to-fetch#:~:text=fetch()%20allows%20you%20to,the%20complex%20API%20of%20XMLHttpRequest." rel="noopener noreferrer"&gt;AJAX requests to the API&lt;/a&gt; to get information back.&lt;/p&gt;

&lt;p&gt;You may encounter the term &lt;strong&gt;RESTful API&lt;/strong&gt; while doing web development. Don’t get confused, It is also a code but it follows a certain &lt;a href="https://en.wikipedia.org/wiki/Representational_state_transfer#Architectural_properties" rel="noopener noreferrer"&gt;architectural style&lt;/a&gt; and uses &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods" rel="noopener noreferrer"&gt;HTTP requests&lt;/a&gt; to access and use data. That data can be used to GET, PUT, POST and DELETE data types, which refers to the reading, updating, creating and deleting of operations concerning resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But in a nutshell, It is just code that&lt;/strong&gt; &lt;a href="https://en.wikipedia.org/wiki/API_writer#:~:text=An%20API%20writer%20is%20a,system%20architects%2C%20and%20system%20designers." rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;somebody else&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;has written to make our life a little bit easier!&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  APIs in the context of Web
&lt;/h1&gt;

&lt;p&gt;APIs are to the Internet what switchboard operators were to early telecommunications!&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%2Fmiro.medium.com%2Fmax%2F2240%2F1%2AAtPMYpX3JcVwjErZ_L9PNw.gif" 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%2Fmiro.medium.com%2Fmax%2F2240%2F1%2AAtPMYpX3JcVwjErZ_L9PNw.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like how switchboard operators used to connect calls, APIs enables &lt;em&gt;communication between applications or software&lt;/em&gt;. An API or application programming interface is a part of a remote server that &lt;strong&gt;&lt;em&gt;receives requests&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;sends responses&lt;/em&gt;&lt;/strong&gt; when you navigate to a website in your browser.&lt;/p&gt;

&lt;p&gt;Take &lt;a href="https://polymathsomnath.medium.com" rel="noopener noreferrer"&gt;medium.com&lt;/a&gt; for example, A request for data goes out to Medium’s remote server. Once your browser receives the data and processes the code response, the browser displays Medium Page. In this case, Medium’s server is the API that enabled communication and allowed you to access the webpage.&lt;/p&gt;

&lt;p&gt;What is happening here is that your request goes to a code that someone else wrote and stored on the server. It provided you access to the current page that is stored somewhere in the remote server.&lt;/p&gt;

&lt;p&gt;Your request doesn’t go to the server directly! It goes to an API, and that API decides what to do with 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%2Fmiro.medium.com%2Fmax%2F2002%2F1%2AWVOuLdAW42IcUNUZJ9MxBA.gif" 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%2Fmiro.medium.com%2Fmax%2F2002%2F1%2AWVOuLdAW42IcUNUZJ9MxBA.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Client(left), API (Blue bolt), and Server(right)&lt;/p&gt;

&lt;p&gt;API are also enables &lt;strong&gt;interaction&lt;/strong&gt; and &lt;strong&gt;data alteration&lt;/strong&gt; between two sites like when a webpage has a share to Twitter button, clicking this button triggers communication with your Twitter account, and alters your account by adding a new Tweet.&lt;/p&gt;

&lt;p&gt;Now, this code or API can take many forms depending upon where it is being used. It will get a name respective to that area. To name a few, we have&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Open APIs&lt;/strong&gt; or &lt;strong&gt;Public APIs:&lt;/strong&gt; These are  publicly available to developers and other users with minimal restriction.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Partner APIs:&lt;/strong&gt; These  APIs exposed by/to the strategic business partners. They are not available publicly and need specific entitlement to access them.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Internal APIs or Private APIs:&lt;/strong&gt; These are  hidden from external users and only exposed by internal systems. It is not meant for consumption outside of the company but rather for use across different internal development teams for better productivity and reuse of services.&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%2Fmiro.medium.com%2Fmax%2F2272%2F1%2AB7VbTJM2DzKiUgBjfc8JCw.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%2Fmiro.medium.com%2Fmax%2F2272%2F1%2AB7VbTJM2DzKiUgBjfc8JCw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bird’s eye view 🦅&lt;/p&gt;

&lt;p&gt;Beyond the difference between internal, partner, open APIs, we should mention another approach to categorize APIs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Data APIs&lt;/strong&gt; provide CRUD access to underlying data sets for various databases or SaaS cloud providers.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Internal service APIs&lt;/strong&gt; consist of exposing internal services, reflecting parts of internal processes, or some complex actions.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;External service APIs&lt;/strong&gt; are third-party services that can be embedded into the existing services of the company to bring additional value.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;User experience APIs&lt;/strong&gt; leverage composite APIs to help app developers provide the right experience for each specific device (desktop, mobile, tablet, VPA, IoT).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;APIs may be further classified as local, web, or program APIs:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Local APIs&lt;/strong&gt; is the original form, from which the name came. They offer OS or &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Middleware" rel="noopener noreferrer"&gt;middleware&lt;/a&gt; services to application programs. Microsoft’s &lt;a href="https://dotnet.microsoft.com/learn/dotnet/what-is-dotnet" rel="noopener noreferrer"&gt;.NET&lt;/a&gt; APIs, the &lt;a href="https://en.wikipedia.org/wiki/Telephony_Application_Programming_Interface" rel="noopener noreferrer"&gt;TAPI (Telephony API)&lt;/a&gt; for voice applications, and database access APIs are examples of the local API form.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web APIs&lt;/strong&gt; are designed to represent widely used resources like &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML" rel="noopener noreferrer"&gt;HTML&lt;/a&gt; pages and are accessed using a simple &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP" rel="noopener noreferrer"&gt;HTTP&lt;/a&gt; protocol. Any web &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/URL" rel="noopener noreferrer"&gt;URL&lt;/a&gt; activates a web API. Web APIs are often called &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/REST" rel="noopener noreferrer"&gt;REST (representational state transfer)&lt;/a&gt; or &lt;a href="https://en.wikipedia.org/wiki/Overview_of_RESTful_API_Description_Languages" rel="noopener noreferrer"&gt;RESTful&lt;/a&gt;.(We discussed it above)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Program APIs&lt;/strong&gt; are based on &lt;a href="https://en.wikipedia.org/wiki/Remote_procedure_call" rel="noopener noreferrer"&gt;remote procedure call (RPC)&lt;/a&gt; technology that makes a remote program component appear to be local to the rest of the software. &lt;a href="https://en.wikipedia.org/wiki/Service-oriented_architecture" rel="noopener noreferrer"&gt;Service oriented architecture (SOA)&lt;/a&gt; APIs, such as Microsoft*&lt;em&gt;’&lt;/em&gt;*s WS-series of APIs, are program APIs.&lt;/p&gt;

&lt;h1&gt;
  
  
  API examples in the developer community
&lt;/h1&gt;

&lt;p&gt;Companies like Facebook, Google, and Yahoo publish APIs to encourage developers to build on their capabilities. These APIs have given us everything from new internet features that browse the sites of other services, to mobile device apps that offer easy access to web resources.&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%2Fmiro.medium.com%2Fmax%2F3504%2F1%2Aw-OMMg4t1kcBfLi3u4Zb5g.gif" 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%2Fmiro.medium.com%2Fmax%2F3504%2F1%2Aw-OMMg4t1kcBfLi3u4Zb5g.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;New features, such as &lt;a href="https://en.wikipedia.org/wiki/Content_delivery_network" rel="noopener noreferrer"&gt;&lt;strong&gt;content delivery&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://developers.google.com/web/updates/2018/06/ar-for-the-web" rel="noopener noreferrer"&gt;&lt;strong&gt;augmented reality&lt;/strong&gt;&lt;/a&gt;, and novel applications of wearable technology, are created in large part through these APIs.&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%2Fmiro.medium.com%2Fmax%2F3504%2F1%2AXwvN78h97P5jF9cmSqDo3g.gif" 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%2Fmiro.medium.com%2Fmax%2F3504%2F1%2AXwvN78h97P5jF9cmSqDo3g.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next time, Whenever you hear of the word API, Think of it as a code that allows two software programs to communicate with each other by running back and forth between &lt;em&gt;applications&lt;/em&gt;, &lt;em&gt;databases&lt;/em&gt;, and &lt;em&gt;devices&lt;/em&gt; to deliver data and create connectivity.&lt;/p&gt;

&lt;h1&gt;
  
  
  What we have learned
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  API is some code that you didn’t write yourself, and that code has some methods that you are allowed to use.&lt;/li&gt;
&lt;li&gt;  In context of web, an API is a part of a remote server that &lt;strong&gt;&lt;em&gt;receives requests&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;sends responses&lt;/em&gt;&lt;/strong&gt; when you navigate to a website in your browser.&lt;/li&gt;
&lt;li&gt;  API can take many forms depending upon where it is being used for example &lt;strong&gt;Open APIs&lt;/strong&gt; or &lt;strong&gt;Public APIs, Partner API, Internal Or Private API.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  It can further be classified into &lt;strong&gt;Local API, Web API, Program API.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  In short API is code that allows two software programs to communicate with each other.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, I hope you have a clear understanding of what an API is and its various nuances. I have seen people struggling with this term. Looking at it from a broader perspective will put an end to the struggle, that people have while learning this fancy term, which they call an &lt;strong&gt;API&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you still have any questions, you can ask them in comments or reach out to me on my&lt;/strong&gt; &lt;a href="https://twitter.com/TweetsbySoma" rel="noopener noreferrer"&gt;&lt;strong&gt;Twitter&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;. 🙏&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you found this article helpful in someway then consider sharing it with others. Let me know your views on it, because to me &lt;strong&gt;it matters!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Take Care! See you in &lt;a href="https://dev.to/polymathsomnath"&gt;my other post&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>What's inside the world most popular programming language?</title>
      <dc:creator>Somnath Singh</dc:creator>
      <pubDate>Fri, 02 Oct 2020 09:24:53 +0000</pubDate>
      <link>https://dev.to/polymathsomnath/what-s-inside-the-world-most-popular-programming-language-9cc</link>
      <guid>https://dev.to/polymathsomnath/what-s-inside-the-world-most-popular-programming-language-9cc</guid>
      <description>&lt;p&gt;&lt;strong&gt;A guide for the Ignorant Programmers.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I have tried to explain the concepts using very basic level of English language, so that a lot of newcomers can understand it without getting an imposter syndrome attack 😂&lt;/p&gt;
&lt;/blockquote&gt;



&lt;h1&gt;
  
  
  INTRODUCTION
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;A programming language is like a natural, human language in that it favors certain metaphors, images, and ways of thinking.&lt;br&gt;
— Mindstorms: Children, Computers, and Powerful Ideas, Seymour Papert (1980)&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt; &lt;br&gt;
We define programming, as a general human activity, to mean the act of extending or changing a system’s functionality. Programming is a widespread activity that is done both by non-specialists (e.g., consumers who change the settings of their alarm clock or cellular phone) and specialists (computer programmers, the audience for this article).&lt;br&gt;
&lt;br&gt;&lt;br&gt; &lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;JavaScript&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt; &lt;br&gt;
It is &lt;strong&gt;the&lt;/strong&gt; most popular Programming language today.&lt;br&gt;
Today, Some of the most powerful Software are written in JavaScript.&lt;br&gt;
But how many folks do actually understand this language?&lt;br&gt;
Probably this the only language which is used(usually in scripts) before it is fully understood.&lt;br&gt;
JavaScript is a powerful programming language but Weird at the same time.&lt;br&gt;
Yet we can’t deny this fact that overall it is a beautiful Programming language.&lt;/p&gt;



&lt;h1&gt;
  
  
  So,
&lt;/h1&gt;

&lt;p&gt;Have you Ever Wondered, how do those assortments of programming statements tell the Computer what to do?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Statements like a = a + 2 are helpful for developers when reading and writing, but are not actually in a form the computer can directly understand.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;So an uncommon utility on the Computer (either a &lt;a href="https://www.youtube.com/watch?v=e4ax90XmUBc" rel="noopener noreferrer"&gt;&lt;em&gt;interpreter or a compiler&lt;/em&gt;&lt;/a&gt;) is utilized to decipher the code you compose into directions that a Computer can comprehend!&lt;/p&gt;



&lt;h2&gt;
  
  
  For some computer languages, this translation of commands is typically done from top to bottom, line by line, every time the program is run, which is usually called &lt;strong&gt;&lt;em&gt;interpreting the code.&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;



&lt;h2&gt;
  
  
  For other languages, the translation is done ahead of time, called compiling the code, so when the program runs later, what’s running is actually the already compiled computer instructions ready to go.
&lt;/h2&gt;



&lt;blockquote&gt;
&lt;p&gt;It’s typically asserted that &lt;strong&gt;&lt;em&gt;JavaScript is interpreted&lt;/em&gt;&lt;/strong&gt;, because your JavaScript source code is processed each time it’s run. &lt;a href="https://softwareengineering.stackexchange.com/questions/138521/is-javascript-interpreted-by-design" rel="noopener noreferrer"&gt;But that’s not entirely accurate.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The JavaScript engine actually compiles the program on the fly and then immediately runs the compiled code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt; &lt;br&gt;
In this article we will LEARN about some essential concepts that will help you to understand what actually happens under the hood.&lt;br&gt;
And by the end of the article you will have a clear understanding of what actually happens when you write a JavaScript CODE&lt;/p&gt;



&lt;p&gt;Concepts that we will learn here are :&lt;/p&gt;



&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Syntax Parsers&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Execution Contexts&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Lexical Environments&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;GOAL&lt;/strong&gt; : Understanding Syntax Parsers, Execution Contexts, and Lexical Environments in a Simple Language.
&lt;/h1&gt;



&lt;blockquote&gt;
&lt;p&gt;All three of these are complicated sounding terms that actually aren’t that difficult to understand.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;h1&gt;
  
  
  SYNTAX PARSER :
&lt;/h1&gt;

&lt;p&gt;A PROGRAM THAT READS YOUR CODE AND DETERMINES WHAT IT DOES AND IF IT’S GRAMMAR OR SYNTAX IS VALID&lt;/p&gt;

&lt;p&gt;So when you write JavaScript it isn’t magically directly telling the computer what to do , you are &lt;a href="https://esprima.org/demo/parse.html" rel="noopener noreferrer"&gt;abstracted away&lt;/a&gt; from all of that you are writing code! but then someone else or other people built programs that convert your JavaScript into something the computer can understand.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Was that too hard to comprehend?&lt;br&gt;
No, Right?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anyways&lt;/strong&gt;, &lt;br&gt;
Those programs are called compilers and at times they also have to do with interpreters, but those programs &lt;a href="https://www.youtube.com/watch?v=e4ax90XmUBc" rel="noopener noreferrer"&gt;&lt;em&gt;interpreters and compilers&lt;/em&gt;&lt;/a&gt; do the process the work of actually reading your code &lt;a href="https://www.youtube.com/watch?v=QXjU9qTsYCc" rel="noopener noreferrer"&gt;&lt;em&gt;character by character&lt;/em&gt;&lt;/a&gt; and determining if the syntax is valid and then implementing that syntax in a way the computer can understand,&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;so when you’re thinking about your code think of it more like :&lt;/strong&gt;
&lt;/h1&gt;

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

&lt;h2&gt;
  
  
  &lt;strong&gt;and a&lt;/strong&gt; &lt;a href="https://www.youtube.com/watch?v=e4ax90XmUBc" rel="noopener noreferrer"&gt;&lt;strong&gt;program&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;that is going to convert what computer can understand !&lt;/strong&gt;
&lt;/h2&gt;

&lt;h1&gt;
  
  
  Something like this:
&lt;/h1&gt;

&lt;p&gt;&lt;br&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%2Fmiro.medium.com%2Fmax%2F2212%2F1%2AFXhTiEYu4AhvEnp7YIFWUg.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%2Fmiro.medium.com%2Fmax%2F2212%2F1%2AFXhTiEYu4AhvEnp7YIFWUg.png" alt="Image for post"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;If you have a &lt;strong&gt;function&lt;/strong&gt; with the variable, then that function and variable will be represented in memory but it’s being translated from what you have written what is more human readable to what the computer can understand. There’s a compiler or an interpreter between those two things and part of that is a &lt;strong&gt;&lt;em&gt;syntax parser&lt;/em&gt;&lt;/strong&gt; so, it’s going through your code&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;character by character like f /u/ n/ c/ t/ i/ o/ n&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  That is, it reads your code in characters
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;and it says : Oh! that’s function 😃 ,So there should be a space after this ! and then the next thing I see up until the parenthesis &lt;strong&gt;( )&lt;/strong&gt; will be the name of the function,&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;above &lt;strong&gt;&lt;em&gt;Greet&lt;/em&gt;&lt;/strong&gt; is next thing the computer sees up until the parenthesis &lt;strong&gt;( )&lt;/strong&gt; so it assumes that &lt;strong&gt;&lt;em&gt;Greet&lt;/em&gt;&lt;/strong&gt; will be the name of the function.&lt;/p&gt;

&lt;p&gt;And all this gets &lt;em&gt;translated by the systems that someone else wrote&lt;/em&gt; but that also means that in that translation process ,the programmers who wrote the compiler can choose to do extra stuff .&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Your code is not what’s actually being given to the computer but a translation of it and so along the way the engine that is interpreting your code can decide to do other things those programmers could have chosen to do something else and in fact that’s going to come up as an important element of understanding JavaScript so that’s impacts parsers and thinking about the programs that are actually running every time you run your JavaScript code that intermediate program that’s creating your code.&lt;br&gt;
&lt;br&gt;&lt;br&gt; &lt;/p&gt;

&lt;h1&gt;
  
  
  LEXICAL ENVIRONMENT :
&lt;/h1&gt;



&lt;blockquote&gt;
&lt;p&gt;The &lt;em&gt;word lexical means having to do with words or grammar&lt;/em&gt; so we’re talking about the code you’re writing it’s syntax it’s vocabulary !&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;Now a &lt;strong&gt;lexical environment&lt;/strong&gt; exists in programming languages in &lt;strong&gt;which&lt;/strong&gt;,where you write something which is &lt;em&gt;important.&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;It sounds kind of funny but actually not every programming language is that way, but remember we said you might have some code.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
let’s say a function with a variable inside of it the variable sits lexically inside the function ,that is : &lt;em&gt;physically the code that you’re writing&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&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%2Fmiro.medium.com%2Fmax%2F1184%2F1%2Ax4IKK3eLfWn6i7gutS0kcg.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%2Fmiro.medium.com%2Fmax%2F1184%2F1%2Ax4IKK3eLfWn6i7gutS0kcg.png" alt="Image for post"&gt;&lt;/a&gt;&lt;/p&gt;
function with a variable inside of it.





&lt;p&gt;that’s where it sits but remember we said that your code is not what’s actually given directly to the computer but it’s translated into something the computer can understand&lt;/p&gt;



&lt;p&gt;In programming languages &lt;strong&gt;where the lexical environment is important&lt;/strong&gt; that means that where you see things written gives you an idea of where it will actually sit in the computer’s memory of how it will interact with other &lt;strong&gt;variables and functions&lt;/strong&gt; and elements of the program and that’s because the program or the compiler that’s converting your code to those instructions cares about where you put things it makes decisions that syntax parts are going through everything makes decisions so when we talk about the lexical environment of something in the code we’re talking about where it’s written and what surrounds it got that.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt; &lt;br&gt;
To help manage the code that is running there are lots of lexical environments areas of the code that you’re looking at physically but which one is currently actually running is managed via what’s called&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;EXECUTION CONTEXT:&lt;/strong&gt;
&lt;/h1&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;A WRAPPER TO HELP MANAGE THE CODE THAT IS RUNNING&lt;/strong&gt;
&lt;/h1&gt;



&lt;blockquote&gt;
&lt;p&gt;There are lots of lexical environments which one is currently running and managed via execution contexts.it contain things beyond what you have written in your code!&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;And in execution context contains your code ,the running code and it’s running your code, but it also can contain things beyond what you’ve written in your code because remember again your code is being translated being processed by a whole other feature a whole other set of programs that someone else wrote and so it’s executing your code and it can do other things as well and that’s what’s happening inside JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt; &lt;br&gt;
&lt;strong&gt;Execution context&lt;/strong&gt; is whole topic by itself which we will deal in some other article.&lt;/p&gt;

&lt;h1&gt;
  
  
  How was the Post ? Tell me in the comments.
&lt;/h1&gt;

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