<?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: Shashank Soni</title>
    <description>The latest articles on DEV Community by Shashank Soni (@shashanksoni61).</description>
    <link>https://dev.to/shashanksoni61</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F710793%2F5b04ff8c-4a60-4a84-9c41-9998f35e626a.jpeg</url>
      <title>DEV Community: Shashank Soni</title>
      <link>https://dev.to/shashanksoni61</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shashanksoni61"/>
    <language>en</language>
    <item>
      <title>Null vs Undefined in Javascript</title>
      <dc:creator>Shashank Soni</dc:creator>
      <pubDate>Sat, 12 Feb 2022 18:23:23 +0000</pubDate>
      <link>https://dev.to/shashanksoni61/null-vs-undefined-in-javascript-2074</link>
      <guid>https://dev.to/shashanksoni61/null-vs-undefined-in-javascript-2074</guid>
      <description>&lt;h3&gt;
  
  
  Null is an assignment value. It can be assigned to a variable as a representation of no value:
&lt;/h3&gt;

&lt;p&gt;There are two features of null you should understand&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt; is an empty or non-existent value.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt; must be assigned&lt;/li&gt;
&lt;li&gt;When you assign &lt;code&gt;null&lt;/code&gt; to a variable, you are declaring that this value is explicitly empty.
&lt;/li&gt;
&lt;/ol&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;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&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;age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Undefined usually means a variable has been declared, but not defined.
&lt;/h3&gt;

&lt;p&gt;When you try to access a &lt;code&gt;property&lt;/code&gt; of an &lt;code&gt;object&lt;/code&gt; that doesn't exist you will get &lt;code&gt;undefined&lt;/code&gt; in return.&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;shashank&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;Shashank&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;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;shashank&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="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  Both  &lt;code&gt;null&lt;/code&gt;and  &lt;code&gt;undefined&lt;/code&gt;are primitive values in JavaScript.&lt;/li&gt;
&lt;li&gt;  When you do loose equality check on both it returns &lt;code&gt;true&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because both are considered &lt;code&gt;falsy&lt;/code&gt; values.&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  null is an assigned value. It means &lt;code&gt;nothing&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  undefined typically means a variable has been declared but not defined yet.&lt;/li&gt;
&lt;li&gt;  null and undefined are &lt;code&gt;falsy&lt;/code&gt; values.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;null&lt;/code&gt;!==  &lt;code&gt;undefined&lt;/code&gt; (strict equality) , but  &lt;code&gt;null&lt;/code&gt;  ==  &lt;code&gt;undefined&lt;/code&gt; ( loose equality)&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>A better way of importing Images (even SVGs) in React Js</title>
      <dc:creator>Shashank Soni</dc:creator>
      <pubDate>Sun, 06 Feb 2022 13:16:51 +0000</pubDate>
      <link>https://dev.to/shashanksoni61/a-better-way-of-importing-images-even-svgs-in-react-js-4di2</link>
      <guid>https://dev.to/shashanksoni61/a-better-way-of-importing-images-even-svgs-in-react-js-4di2</guid>
      <description>&lt;p&gt;Importing static images from your &lt;code&gt;assets&lt;/code&gt; folder into a React component can become a tedious task if you have to import multiple images, and it also changes your overall component's aesthetics . Let's understand it by looking at an example&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J7X98CP3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/if7ty05gkc6s49acuryx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J7X98CP3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/if7ty05gkc6s49acuryx.jpg" alt="footer-html-template" width="813" height="647"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and now you want to convert it into a React component&lt;br&gt;
Our traditional approach might be like this&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vnTpubq8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6jmv8xbir2aelpj3bpx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vnTpubq8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6jmv8xbir2aelpj3bpx.jpg" alt="react-footer-jsx" width="880" height="580"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;here we are using multiple import statements, suppose if we have more icons , our import statement may increase as well , and it will become messy &amp;amp; visually unpleasant (at least for me),&lt;br&gt;
So I wanted to change this , and found a better way to deal with this situation.&lt;br&gt;
I created a javascript file inside my assets folder, and imported all the images, related to project, into this file.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PxPWSAt1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lszs0w5hoktax95o9hl1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PxPWSAt1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lszs0w5hoktax95o9hl1.jpg" alt="Folder-structure" width="267" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I have created a file called &lt;code&gt;images.js&lt;/code&gt; which contains path of images as an object&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--21i-M4UK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6swa25yukbcfgbm9afic.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--21i-M4UK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6swa25yukbcfgbm9afic.jpg" alt="importing images in image js file" width="880" height="595"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You have to use &lt;code&gt;.default&lt;/code&gt;after &lt;code&gt;require&lt;/code&gt; statement for importing SVGs  otherwise it will not display the SVG . and for png/jpg/jpeg you can remove &lt;code&gt;.default&lt;/code&gt;&lt;br&gt;
and now , to use it, all you have to do is, import this &lt;code&gt;images.js&lt;/code&gt; file and use the image using &lt;code&gt;. notation&lt;/code&gt;,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--__21HO_n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ox5m2gg80rlinxdu475i.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--__21HO_n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ox5m2gg80rlinxdu475i.jpg" alt="importing img using image js file" width="697" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>svg</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding 'this' in Javascript </title>
      <dc:creator>Shashank Soni</dc:creator>
      <pubDate>Sun, 06 Feb 2022 11:00:09 +0000</pubDate>
      <link>https://dev.to/shashanksoni61/understaing-this-in-javascript-42h0</link>
      <guid>https://dev.to/shashanksoni61/understaing-this-in-javascript-42h0</guid>
      <description>&lt;p&gt;The &lt;strong&gt;this&lt;/strong&gt; keyword is an extremely important concept to understand in Javascript ,and many beginners, like me, find it difficult to understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;this&lt;/strong&gt; keyword/variable is a special variable that is created for every &lt;em&gt;execution context&lt;/em&gt;(the 'environment' a function executes in).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So what is stored in 'this' keyword ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In General terms , the &lt;strong&gt;this&lt;/strong&gt; keyword will always take the value of the owner of the function  in which the 'this' keyword is used.&lt;br&gt;
or we can say that it points to the owner of the function.&lt;/p&gt;

&lt;p&gt;Which means the value of this keyword is not static, it depends on how the function is actually called, and its value is only assigned when the function is actually called.&lt;/p&gt;

&lt;p&gt;let's analyze different ways in which function can be called&lt;/p&gt;
&lt;h2&gt;
  
  
  1. As a Method
&lt;/h2&gt;

&lt;p&gt;means as a function attached to an object.&lt;br&gt;
When we call a method, the this keyword inside that method will simply point to the object in which the method is called. Or in other words, it points to the &lt;code&gt;object&lt;/code&gt; that is calling the method.&lt;br&gt;
Ex.&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;shashank&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;shashank&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;year&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1998&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;findAge&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="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="c1"&gt;// this = shashank object &lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2022&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="nx"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;shashank&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findAge&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 24 &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here the value of &lt;code&gt;this&lt;/code&gt; keyword inside &lt;code&gt;findAge&lt;/code&gt; method is &lt;code&gt;shashank&lt;/code&gt; &lt;code&gt;object&lt;/code&gt;, because &lt;code&gt;shashank&lt;/code&gt; object is calling this method.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Simple Function Call
&lt;/h2&gt;

&lt;p&gt;means not as a &lt;code&gt;method&lt;/code&gt; &amp;amp; not attached to any &lt;code&gt;object&lt;/code&gt;.&lt;br&gt;
In this case the &lt;code&gt;this&lt;/code&gt; keyword will be &lt;code&gt;undefined&lt;/code&gt; (&lt;strong&gt;Only in Strict Mode&lt;/strong&gt;),&lt;br&gt;
if you're not using &lt;code&gt;'strict mode'&lt;/code&gt;( which you should not be doing), the &lt;code&gt;this&lt;/code&gt; keyword will simply point to &lt;code&gt;global&lt;/code&gt; object - meaning the &lt;code&gt;window&lt;/code&gt; object,&lt;br&gt;
(another good reason to use &lt;code&gt;'strict mode'&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;function&lt;/span&gt; &lt;span class="nx"&gt;findUserAge&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="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;findUserAge&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6uBwvRJs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fryozxvjkh0d5lmu2ry.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6uBwvRJs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fryozxvjkh0d5lmu2ry.jpg" alt="simple function call" width="880" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;the reason for getting &lt;code&gt;undefined&lt;/code&gt; in second line is because function &lt;code&gt;findUserAge()&lt;/code&gt; is not returning any value,&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="s1"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;findUserAge&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="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;findUserAge&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OwQBBWNr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xs2ceianos3boeoxbb0m.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OwQBBWNr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xs2ceianos3boeoxbb0m.jpg" alt="when using strict mode" width="880" height="103"&gt;&lt;/a&gt;&lt;br&gt;
the reason for getting two &lt;code&gt;undefined&lt;/code&gt; is because we are using strict mode so &lt;code&gt;this&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt; and in second line its because function &lt;code&gt;findUserAge()&lt;/code&gt; is not returning any value,&lt;/p&gt;
&lt;h2&gt;
  
  
  3.  Arrow Function.
&lt;/h2&gt;

&lt;p&gt;Arrow function do not get their own &lt;code&gt;this&lt;/code&gt; keyword , if you use &lt;code&gt;this&lt;/code&gt; in  an arrow function it will simply be the &lt;code&gt;this&lt;/code&gt; keyword of the surrounding function ( or &lt;code&gt;parent function&lt;/code&gt;)&lt;br&gt;
In technical terms this is called the &lt;code&gt;lexical this keyword&lt;/code&gt; because it simply gets picked up from the outer lexical scope of the arrow 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;shashank&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;shashank&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;year&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1998&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;findAge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Window object&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2022&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="nx"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;shashank&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findAge&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// NaN ( Not a Number)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Function is called as an Event Listener
&lt;/h2&gt;

&lt;p&gt;Then the &lt;code&gt;this&lt;/code&gt; keyword will always point to the DOM element , that the handler function is attached to &lt;/p&gt;

&lt;h2&gt;
  
  
  What is Not the &lt;code&gt;this&lt;/code&gt; keyword
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; does not point to the function itself and also not the variable environment of the function &lt;/p&gt;

&lt;p&gt;There are also some other ways to call a function using &lt;code&gt;call&lt;/code&gt; &lt;code&gt;apply&lt;/code&gt; &amp;amp; &lt;code&gt;bind&lt;/code&gt; method, calling the function using these three methods is called &lt;code&gt;explicit binding&lt;/code&gt; .&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Method&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;this&lt;/code&gt; = Object that is calling the method&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Simple Function Call&lt;/td&gt;
&lt;td&gt;in strict mode &lt;code&gt;this&lt;/code&gt; = undefined, otherwise this = window object&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arrow Function&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;this&lt;/code&gt; = surrounding of function , also called lexical this&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Event Listener&lt;/td&gt;
&lt;td&gt;DOM element , where the handler is attached&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>this</category>
    </item>
  </channel>
</rss>
