<?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: Shahriar Saleh Fahim</title>
    <description>The latest articles on DEV Community by Shahriar Saleh Fahim (@fahim04blue).</description>
    <link>https://dev.to/fahim04blue</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%2F573020%2F6498de6b-b913-4fcf-82ba-d87a83eb37ff.jpeg</url>
      <title>DEV Community: Shahriar Saleh Fahim</title>
      <link>https://dev.to/fahim04blue</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fahim04blue"/>
    <language>en</language>
    <item>
      <title>The myth of JavaScript "this" Keyword</title>
      <dc:creator>Shahriar Saleh Fahim</dc:creator>
      <pubDate>Fri, 13 Aug 2021 18:58:50 +0000</pubDate>
      <link>https://dev.to/fahim04blue/the-myth-of-javascript-this-keyword-j5h</link>
      <guid>https://dev.to/fahim04blue/the-myth-of-javascript-this-keyword-j5h</guid>
      <description>&lt;h2&gt;
  
  
  A practical example of “this”:
&lt;/h2&gt;

&lt;p&gt;Suppose you have a nice house and the house number is 15 JS Road. Your wife wants to paint the house. So she tells you “We Need to paint &lt;strong&gt;this&lt;/strong&gt; house”. Notice that she is referring to the house with a &lt;strong&gt;this&lt;/strong&gt; keyword. She isn’t saying we need to paint 15 JS Road House. You both are already inside that house. So she is just saying &lt;strong&gt;this&lt;/strong&gt; house. The meaning of &lt;strong&gt;this&lt;/strong&gt; is so simple like that. Practically there is no difference between the &lt;strong&gt;this&lt;/strong&gt; in real life and the &lt;strong&gt;this&lt;/strong&gt; in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the &lt;strong&gt;this&lt;/strong&gt; keyword is in JS?
&lt;/h2&gt;

&lt;p&gt;It helps a function to be reused in a different context.&lt;/p&gt;

&lt;p&gt;There are 4 general rules. If you know these 4 rules you will have an idea about which object &lt;strong&gt;this&lt;/strong&gt; is pointing at.&lt;/p&gt;

&lt;p&gt;The rules are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Implicit Binding&lt;/li&gt;
&lt;li&gt;Explicit Binding&lt;/li&gt;
&lt;li&gt;New Binding&lt;/li&gt;
&lt;li&gt;Window Binding&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I will now explain each rule with coding examples so that the topic will become more clearer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Implicit Binding&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//example-1&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fahim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fahim&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;printUserName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// This ""this".name" refers to the name property of the current object it is in.&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;fahim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;printUserName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//fahim&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So here when we call printUserName function first we have to check if there is a “.” notation before it and if there is one then the “this” inside that function is referring to the object in which function is in. Here the function is inside the “fahim” object and it is a property of the object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Explicit Binding&lt;/strong&gt;&lt;br&gt;
      &lt;strong&gt;2.1 .Call()&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;////Explicit Binding(call)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;printName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//fahim&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fahim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fahim&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;printName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fahim&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in Implicit Binding, we saw that the &lt;strong&gt;this&lt;/strong&gt; keyword refers to the object it is in. Now, what happens if we take the function out of the object and declare it globally or in another context and try to print the &lt;strong&gt;this.name&lt;/strong&gt;.There is a &lt;strong&gt;.call()&lt;/strong&gt; function in JS which is nothing more than calling a function explicitly. &lt;strong&gt;.call()&lt;/strong&gt; receives an object as the first parameter which means the function is called within the context of the object fahim here. So we are explicitly telling the definition of &lt;strong&gt;this&lt;/strong&gt; inside the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;printName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;v3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//Fahim is Hardworking,All Rounder &amp;amp; Best Player&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fahim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fahim&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hardworking&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;All Rounder&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Best Player&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;printName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fahim&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another use case of the &lt;strong&gt;.call()&lt;/strong&gt; function is for its 2nd parameter it can take unlimited parameters. We can pass these parameters through the main function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.2 .Apply()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now here we can see we have to pass a lot of parameters in the &lt;strong&gt;.call()&lt;/strong&gt; function. So there is an alternative way of doing that. We can take all those parameters inside an array and pass that array inside a &lt;strong&gt;.apply()&lt;/strong&gt; function. It does the same work as &lt;strong&gt;.call()&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;printName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;v3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//Fahim is Hardworking,All Rounder &amp;amp; Best Player&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fahim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fahim&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hardworking&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;All Rounder&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Best Player&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;printName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fahim&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.3 .Bind()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;.bind()&lt;/strong&gt; also does the same work as &lt;strong&gt;.call()&lt;/strong&gt;. In  &lt;strong&gt;.call()&lt;/strong&gt; we are directly calling the function. In  &lt;strong&gt;.bind()&lt;/strong&gt; it returns an instance of a function. So if store it in a variable. Then we can call the variable and it will do the job.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;printName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;v3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//Fahim is Hardworking,All Rounder &amp;amp; Best Player&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fahim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fahim&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hardworking&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;All Rounder&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;v3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Best Player&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;printName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fahim&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;newName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So there is no confusion about the definition of &lt;strong&gt;this&lt;/strong&gt; in Explicit Binding as we are explicitly defining it here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. New Binding&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//let this = Object.create(null)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years old`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;//return this&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Fahim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fahim&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Ani&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ani&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So here &lt;code&gt;Person&lt;/code&gt; is a constructor function. It takes two parameters name and age. We created a &lt;code&gt;new Person&lt;/code&gt; named Fahim. So by default JS creates an object named &lt;strong&gt;this&lt;/strong&gt; inside the constructor function. So, &lt;code&gt;this.name&lt;/code&gt; points to the new Object created by JS. The name &lt;code&gt;Fahim&lt;/code&gt; and age &lt;code&gt;24&lt;/code&gt; is passed to the constructor function and &lt;code&gt;this.name&lt;/code&gt; and &lt;code&gt;this.age&lt;/code&gt; receives it and returns the new object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Window Binding&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PrintName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//undefined&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sakib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sakib&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;PrintName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When all 3 rules of binding don’t work then &lt;strong&gt;this&lt;/strong&gt; will just point at the window. Hence we are getting &lt;code&gt;undefined&lt;/code&gt;. We can prove that &lt;strong&gt;this&lt;/strong&gt; is equal to window if we console.log it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PrintName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//true&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//undefined&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sakib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sakib&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;PrintName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get out of this weird behavior of getting undefined we can fix it by writing “use strict”. Then JS will show us the error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PrintName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//throws error&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sakib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sakib&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;PrintName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Note:
&lt;/h2&gt;

&lt;p&gt;The first 3 rules all are applied to normal JavaScript functions but if you are using &lt;strong&gt;Arrow Function&lt;/strong&gt; then simply &lt;strong&gt;Arrow Function&lt;/strong&gt; is not concerned with &lt;strong&gt;this&lt;/strong&gt; and even &lt;strong&gt;Arrow Function&lt;/strong&gt; is introduced to decrease the confusion of using &lt;strong&gt;this&lt;/strong&gt; keyword. The value of &lt;strong&gt;this&lt;/strong&gt; keyword in &lt;strong&gt;Arrow Function&lt;/strong&gt; is whatever context the &lt;strong&gt;Arrow Function&lt;/strong&gt; is in. It can be window/global, function or object.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Some tricky JavaScript questions you should know</title>
      <dc:creator>Shahriar Saleh Fahim</dc:creator>
      <pubDate>Sat, 08 May 2021 13:50:51 +0000</pubDate>
      <link>https://dev.to/fahim04blue/some-tricky-javascript-questions-you-should-know-6lh</link>
      <guid>https://dev.to/fahim04blue/some-tricky-javascript-questions-you-should-know-6lh</guid>
      <description>&lt;p&gt;Hello, all!!! Hope you guys are safe. Today I'll talk about some tricky parts of JavaScript which you should definitely know to increase your knowledge in JS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Truthy &amp;amp; Falsy Values&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's start with the easy one. Sometimes you may write conditions where you would need to define if a variable is true theb it might do something and if it is false it might do something else. Here's an example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const age=4
if(age&amp;gt;0){
console.log('True')
}
else{
console.log('False')
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you declared a variable called age and gave a condition that if &lt;code&gt;age&amp;gt;0&lt;/code&gt; then it will print &lt;code&gt;True&lt;/code&gt; otherwise it will print &lt;code&gt;False&lt;/code&gt;. Pretty straight right? Even if you don't write &lt;code&gt;age&lt;/code&gt; instead of &lt;code&gt;age&amp;gt;0&lt;/code&gt; it will still print &lt;code&gt;True&lt;/code&gt;(Try yourself in a IDE). It's happening because as variable age has a value other than 0 ,assigned to it it will always return &lt;code&gt;True&lt;/code&gt; . So 0 here is called a &lt;code&gt;Falsy&lt;/code&gt; value in JS.&lt;/p&gt;

&lt;p&gt;So can you guess what should happen if I create a variable named &lt;code&gt;name&lt;/code&gt;and assign &lt;code&gt;empty string&lt;/code&gt; to it . What will be answer?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name=''
if(name){
console.log('True')
}
else{
console.log('False')
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you ran the code you know the result. The answer is &lt;code&gt;False&lt;/code&gt;.So, you may already have a guess that JS basically treats any empty or null value as &lt;code&gt;Falsy&lt;/code&gt; values. So you might be asking what about empty arrays and objects? Both of them are &lt;code&gt;Truthy&lt;/code&gt; values because when you initiate an array or object without a property you are still creating a object. Objects are considered &lt;code&gt;True&lt;/code&gt; in JS. Array is also a type of Object. &lt;/p&gt;

&lt;p&gt;Below here is a list of &lt;code&gt;Truthy&lt;/code&gt; and &lt;code&gt;Falsy&lt;/code&gt; values in JS. Please also check them by yourselves in your IDE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Falsy Values&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;number = 0
string = "" (no white space)
undefined
null
NaN
False

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Truthy Values&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'0'
string = " " ( white space)
[] (empty array)
{} (empty object)
true
'false' (It's a string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>trick</category>
    </item>
    <item>
      <title>Your New React Tour Guide</title>
      <dc:creator>Shahriar Saleh Fahim</dc:creator>
      <pubDate>Fri, 07 May 2021 15:56:19 +0000</pubDate>
      <link>https://dev.to/fahim04blue/your-new-react-tour-guide-52</link>
      <guid>https://dev.to/fahim04blue/your-new-react-tour-guide-52</guid>
      <description>&lt;p&gt;Before you read this post , please note that in order to take tour to React you need to have basic understanding of JavaScript, Html and Css.&lt;/p&gt;

&lt;p&gt;Let's first start with What is React.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What is React?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;React is JavaScript library for building complex User Interfaces.It was created by Jordan Walke in 2011 .You may have noticed I said it's library and not a framework. Well it's because React is not the ultimate solution for your problem. It gives you a solid base but to complete a whole application you may need help of other library or frameworks. Frameworks are great . It gives you ready made templates or codes which will help you a lot but for larger application frameworks become a burden programmers. This is programmers tends to work with library which give them freedom to modulate their code bases.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Why React?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, you've been learning JavaScript for 2 months and life is great. Why wouldn't it be ? You can build so many cool apps with JavaScript and show it off with your friends. Now suddenly you have an amazing idea to build a E-commerce app. So you started looking for designs for inspiration and you've finally chosen one. You started Coding 👩‍💻 the logical parts. Suddenly you felt you are writing a lot of duplicate code. For example, your app has a section which contain 20 cards which will be similar in look and different in data.Ok no problem we can always start a foreach loop or map all the details right? Now you are seeing another section requires the same attention and by that time your code is already looking very ugly and not readable at all. &lt;/p&gt;

&lt;p&gt;This is where React comes. The only purpose of React is to build User Interfaces. A User Interface is basically what we see in a website. You just have to tell React what do you want and it will do it for you. Specially for a application which has multiple pages to visit. Building a UI of a medium size application from scratch is not a optimal solution at all. React uses all Html , Css and JavaScript but in a React way . The React language is called JSX . We will describe about JSX in the next section.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript myths you probably did not know</title>
      <dc:creator>Shahriar Saleh Fahim</dc:creator>
      <pubDate>Thu, 06 May 2021 17:58:13 +0000</pubDate>
      <link>https://dev.to/fahim04blue/javascript-that-you-didnot-know-38gm</link>
      <guid>https://dev.to/fahim04blue/javascript-that-you-didnot-know-38gm</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript Types&lt;/li&gt;
&lt;li&gt;Try-Catch&lt;/li&gt;
&lt;li&gt;ES6+: Var vs Let vs Const&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  JavaScript Types &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;You probably heard about primitive values a lot. You probably asked yourself a lot &lt;em&gt;What the heck is a primitive value?&lt;/em&gt; Primitive values are like the sun, which is miles away from us, but it will always be there for us. It will always rise in the east and set at the west, and you can not do anything to change its direction. Primitive values are a constant like the Sun that &lt;em&gt;cannot&lt;/em&gt; be changed. If you look at the below examples,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(typeof(3)); // expected output number
console.log(typeof('Shahriar')); // expected output string
console.log(typeof(undefined)); // expected output undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Numbers&lt;/em&gt; and &lt;em&gt;Strings&lt;/em&gt; are the most common primitive values. Both of them are infinite. Just think it like this if you start counting a number and start writing a string, will there be an end? There are three more types of primitive values. Those are &lt;em&gt;Boolean&lt;/em&gt;, &lt;em&gt;Null&lt;/em&gt; and &lt;em&gt;Undefined&lt;/em&gt;, but they are limited number. Why are they called limited? &lt;em&gt;Boolean&lt;/em&gt; has only two values, &lt;code&gt;True&lt;/code&gt; and &lt;code&gt;False&lt;/code&gt;. There can never be a third &lt;em&gt;Boolean&lt;/em&gt; type just as much there can never be a second &lt;em&gt;Null&lt;/em&gt; and &lt;em&gt;Undefined&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Try-Catch &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;As a programmer, we all encountered numerous errors. The error may occur for a different reason, and you may not even find out where it even came from. In the case of JavaScript, the script &lt;strong&gt;dies&lt;/strong&gt; if it encounters an error. There is a syntax called &lt;code&gt;try-catch&lt;/code&gt;, which helps programmers catch errors more efficiently. The script will not die if your code is inside a &lt;code&gt;try-catch&lt;/code&gt; block. &lt;/p&gt;

&lt;h1&gt;
  
  
  Try-Catch syntax
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;try-catch&lt;/code&gt; syntax has 2 main blocks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {

  // code...

} catch (err) {

  // error handling

}

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

&lt;/div&gt;



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

&lt;ol&gt;
&lt;li&gt;First, the &lt;code&gt;try&lt;/code&gt; block will be executed.&lt;/li&gt;
&lt;li&gt;If there are no &lt;code&gt;errors&lt;/code&gt;, then the &lt;code&gt;catch&lt;/code&gt; block is ignored.&lt;/li&gt;
&lt;li&gt;IF there are &lt;code&gt;errors&lt;/code&gt;, then &lt;code&gt;try&lt;/code&gt; block execution is halted and 
&lt;code&gt;catch&lt;/code&gt; block is executed to catch the error.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;err&lt;/code&gt; variable contains an &lt;code&gt;Error&lt;/code&gt; object with the error details. You can give the &lt;code&gt;err&lt;/code&gt; variable any name you name want. &lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;The &lt;code&gt;try-catch&lt;/code&gt; block only works if your code is runnable. If your code has syntax errors, the &lt;code&gt;try-catch&lt;/code&gt; won't even be executed. It is because JavaScripts first read the code and run it. If an error occurred while reading the code, it is called a &lt;code&gt;parse-time&lt;/code&gt; error. These &lt;code&gt;parse-time&lt;/code&gt; errors can't be recovered. This is because the JS engine can't understand the code properly. The &lt;code&gt;try-catch&lt;/code&gt; only catches errors that occur in valid code. Such errors are called &lt;code&gt;run-time&lt;/code&gt; errors. &lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;try-catch&lt;/code&gt; example
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {

  alert('Start of try runs');  // (1) &amp;lt;--

  lalala; // error, variable is not defined!

  alert('End of try (never reached)');  // (2)

} catch (err) {

  alert(`Error has occurred!`); // (3) &amp;lt;--

}

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;code&gt;try-catch&lt;/code&gt; only works at runtime
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
  {{{{{{{{{{{{
} catch (err) {
  alert("The engine can't understand this code, it's invalid");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more in-depth information about &lt;code&gt;try-catch&lt;/code&gt; please visit this &lt;a href="https://javascript.info/try-catch"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ES6+: Var vs Let vs Const&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;ES stands for ECMAScript. ECMAScript is simply a standard for coding. JavaScript implements ECMAScript. Think it like that ECMAScript is simply a layer over JavaScript, and JavaScript implements the standards of ECMAScript. JavaScript was added to the ECMA standard back in 1997, and that was called ES1. ES6 was released in 2015. From the release of ES6, there came many big changes in JavaScript. One of those changes was &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; keywords. This section will describe more about the differences &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; and their scopes.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Var&lt;/th&gt;
&lt;th&gt;Let&lt;/th&gt;
&lt;th&gt;Const&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Global &amp;amp; function scope&lt;/td&gt;
&lt;td&gt;Block Scope&lt;/td&gt;
&lt;td&gt;Block Scope&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Value can change&lt;/td&gt;
&lt;td&gt;Value can change&lt;/td&gt;
&lt;td&gt;Value can't change&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So the first question is What is a Scope? Scope in JavaScript is very different from other programming languages. Specially people coming from typed language like C,C++ or Java will find it pretty weird. Well think of Scope like a relation between parent world and child world. Child can get access to Parent world but Parent can not access to child world. If you remember this simple information you have understood the fundamentals of Scope in JavaScript. Parent world refers to a variable which is declared openly or in root of the program. It means the variable is not inside a function or a statement.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Var&lt;/code&gt; was heavily used before ES6 introduced &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;. &lt;code&gt;Var&lt;/code&gt;is used withing &lt;em&gt;Global&lt;/em&gt; and &lt;em&gt;function&lt;/em&gt;/&lt;em&gt;local&lt;/em&gt; scope. Now, what is a global scope? &lt;em&gt;Global Scope&lt;/em&gt; is the whole application scope. If you define any variable in the global scope, it can be accessed anywhere in the application. &lt;em&gt;Function&lt;/em&gt;/&lt;em&gt;Local Scope&lt;/em&gt; is defined within a specific function. All the variables declared inside the specific function you can use it.  Think of it like this, &lt;em&gt;Global Scope&lt;/em&gt; is the parent and &lt;em&gt;Function&lt;/em&gt;/&lt;em&gt;Local Scope&lt;/em&gt; is the child. &lt;em&gt;Block Scope&lt;/em&gt; is defined inside brackets. The following picture will help you understand the scoping concept more clearly.&lt;/p&gt;

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

&lt;p&gt;Now let's run this code and find out what's the result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;es6Example&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shahriar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// exists in function scope&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Saleh&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// exists in block scope&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Var Access: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// expected output Shahriar&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Let Access: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// expected output: lastName is not defined.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that we can get the output of &lt;code&gt;firstName&lt;/code&gt; as it is &lt;em&gt;Function Scope&lt;/em&gt;, it can be accessed within the &lt;code&gt;es6Example&lt;/code&gt; function. On the other hand, &lt;code&gt;lastName&lt;/code&gt; variable is undefined because it can not be accessed outside its &lt;em&gt;Block Scope&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Many people seems to have misconception regarding usage of &lt;code&gt;Var&lt;/code&gt; &amp;amp; &lt;code&gt;Let&lt;/code&gt; because both can be used to reassign the value of a variable. Both are very different from each other. &lt;code&gt;Var&lt;/code&gt; works in &lt;em&gt;Global/Function Scope&lt;/em&gt; whereas &lt;code&gt;Let&lt;/code&gt; works in &lt;em&gt;Block Scope&lt;/em&gt;. &lt;code&gt;Var&lt;/code&gt; can be use to redefined a &lt;code&gt;variable&lt;/code&gt; which is very risky. You can redefine a &lt;code&gt;variable&lt;/code&gt; 10000 times and JS will count the last &lt;code&gt;variable&lt;/code&gt;'s value. So ES6 introduced &lt;code&gt;Let&lt;/code&gt; to stop this confusion. You can't redefine a value using &lt;code&gt;Let&lt;/code&gt; but can only reassign it inside it's scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am Shahriar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// expected output: I am Shahriar&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am Fahim&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// expected output: I am Fahim&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
 &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am Fahim&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
 &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am Shahriar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
 &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// SyntaxError: Identifier 'myName' has already been declared. &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Let&lt;/code&gt; &amp;amp; &lt;code&gt;Const&lt;/code&gt; both were added for block scoping. The major difference between &lt;code&gt;Let&lt;/code&gt; &amp;amp; &lt;code&gt;Const&lt;/code&gt; is you can reassign a new value to a variable that is declared using the &lt;code&gt;let&lt;/code&gt; keyword but you can not reassign a new value to a variable that is declared using the &lt;code&gt;const&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// expected output : 6&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// expected output Uncaught TypeError: Assignment to constant variable.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can though update a variable using &lt;code&gt;Const&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Shahriar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;// expected output : { name: 'Shahriar', age: 24 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Curious Case of JavaScript Basics</title>
      <dc:creator>Shahriar Saleh Fahim</dc:creator>
      <pubDate>Wed, 05 May 2021 15:51:16 +0000</pubDate>
      <link>https://dev.to/fahim04blue/a-curious-case-of-javascript-basics-2k24</link>
      <guid>https://dev.to/fahim04blue/a-curious-case-of-javascript-basics-2k24</guid>
      <description>&lt;p&gt;If you are at least familiar with programming languages, you must have heard the names of different programming languages such as C, C++, Java, Python, etc. You may also hear about a language named JavaScript. At a glance, you may think Java and JavaScript maybe cousins. In truth, Java and JavaScript both are two very different languages. JavaScript is a scripting language and its syntax is based on Java and C.JavaScript is the soul of modern web applications. If you turn off your browser's JavaScript and browse a website you'll feel the difference.&lt;/p&gt;

&lt;p&gt;To know the in and outs of a language we have to first learn the building blocks &lt;strong&gt;' the types'&lt;/strong&gt; of a language. JavaScript's types are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;Array&lt;/li&gt;
&lt;li&gt;Function&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We'll look at a few of the most used methods of each type in this blog. Let's start with String.&lt;/p&gt;

&lt;h1&gt;
  
  
  String
&lt;/h1&gt;

&lt;p&gt;Strings are represented in text form. You can make any word or number a string just by keeping those words or numbers inside a quotation mark. For example, &lt;/p&gt;

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

&lt;p&gt;Now that we have some idea of what is a String type is, let us look at some most used methods of String.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String.prototype.includes()&lt;/strong&gt;: Includes method is mostly used while you search for a specific word in a sentence. It returns a boolean answer &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. For example, &lt;/p&gt;

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

&lt;p&gt;Includes is also very case sensitive. For example,&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;String.prototype.concat()&lt;/strong&gt;: Concat method is a way to add two separate strings together. It returns a completely new string after the operation. For example,&lt;/p&gt;

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

&lt;p&gt;Notice that I added white space between the quotation mark which resulted in the whitespace between Hello and World.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String.prototype.slice()&lt;/strong&gt;: You can guess it by the name. The slice method slices the string and returns a completely new String. Slice method has a beginIndex and an optional endIndex For Example,&lt;/p&gt;

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

&lt;p&gt;Note that, the endIndex will always be greater than the beginIndex but what if someone gives a negative endIndex? then the string will start slicing off from the end of the sentence. For Example,&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y3VsH4sv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abmilsx6xtz0a0p49jct.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y3VsH4sv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abmilsx6xtz0a0p49jct.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see that the missing letters 'o' and 'g'. As the endIndex is negative the slice method started slicing off letters in a reverse way. Now, what if someone gives a positive endIndex but it is lower than the beginIndex then the slice method will return an empty string.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;String.prototype.trim()&lt;/strong&gt;: If you ever edited a video you have probably heard of trimming ✂️. The same concept is also applied here. The trim method trims the start and end white space of a String. For example,&lt;/p&gt;

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

&lt;h1&gt;
  
  
  Numbers
&lt;/h1&gt;

&lt;p&gt;Numbers are primitive data types in JavaScript.Unlike many other languages, JavaScript doesn't define a specific type of number such as integer, floating-point, short, long, etc. JavaScript only has one type of number. You can write it with or without a decimal. Now, let us look at some of the popular JavaScript number methods. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;parseInt()&lt;/strong&gt;: As the name suggests parseInt() method parses a string,floating-point number and returns the first integer number. Integer is a number without any decimal point meaning a whole number. It returns NaN(Not a Number) if the number can't be converted to an integer For example,&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8mVBAKKH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nc74uxxu4j0xszfr2joe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8mVBAKKH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nc74uxxu4j0xszfr2joe.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;parseFloat()&lt;/strong&gt;: ParseFloat method is same as parseInt method. Instead of returning a whole number, it returns a number with or without a decimal. For example,&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SiuMwuZU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dvyopd3hedwlzgf0yb2e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SiuMwuZU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dvyopd3hedwlzgf0yb2e.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Arrays
&lt;/h1&gt;

&lt;p&gt;Imagine you have 20 values. Now you want to store the values. You can create 20 variables and assign the numbers in those 20 variables but it is not efficient at all. Instead of creating so many variables, we can create an Array to store those numbers. An array is a special variable that can store more than one value at a time. You can store numbers, strings, and even objects in an array. We can create an array in this way,&lt;/p&gt;

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

&lt;p&gt;Let us look at some most used  Array methods in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array.map()&lt;/strong&gt;: If you ever work with APIs you will know why the map is the most used array method of them all. The map method takes every element of an array and returns a completely new array. For example,&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QRok11NP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbx5dfvp9yo7s2760kyx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QRok11NP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbx5dfvp9yo7s2760kyx.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Array map takes a callback function as a parameter. When the function is called, it scans through every element of an &lt;code&gt;array&lt;/code&gt;. Each time the callback function is executed it adds a new value to the &lt;code&gt;newArray&lt;/code&gt;. The callback function takes at least one argument and it is the current value of the given array. In our case, it is labeled as &lt;code&gt;arr&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array.filter()&lt;/strong&gt;: Imagine you have an array you have set some conditions and you want all the values in return if those values pass the condition. This can be achieved with the filter method. The filter method returns a new array with all the elements which pass the given condition.&lt;/p&gt;

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

&lt;p&gt;As you can see 10, 20, 21, 22, 99, 100 are bigger than 6 hence these values are returned and stored in a new array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array.find()&lt;/strong&gt; : Now imagine the last example with some tweaks. Now you want only the first number returned which fulfills the condition. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ah6nbm4---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ua6ko7tvg985p5asjs7f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ah6nbm4---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ua6ko7tvg985p5asjs7f.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the find method only returns one element. It does not create a new array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array.includes()&lt;/strong&gt;: Same as the String.prototype.includes(), the include method in array searches for a certain value in an array and returns a boolean number &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

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

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