<?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: nehabharati</title>
    <description>The latest articles on DEV Community by nehabharati (@nehabharati).</description>
    <link>https://dev.to/nehabharati</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%2F372997%2Fcd23c3f1-e3b1-4dcd-80a3-96fe0b27e54a.jpg</url>
      <title>DEV Community: nehabharati</title>
      <link>https://dev.to/nehabharati</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nehabharati"/>
    <language>en</language>
    <item>
      <title>5 ways to stay motivated on your coding journey</title>
      <dc:creator>nehabharati</dc:creator>
      <pubDate>Fri, 17 Jul 2020 11:17:50 +0000</pubDate>
      <link>https://dev.to/nehabharati/5-ways-to-stay-motivated-on-your-coding-journey-53d1</link>
      <guid>https://dev.to/nehabharati/5-ways-to-stay-motivated-on-your-coding-journey-53d1</guid>
      <description>&lt;p&gt;If you're learning to code, there's one thing that you need more than your ability to code itself - and that is &lt;strong&gt;MOTIVATION&lt;/strong&gt;. It's hard to stay motivated all the time, in fact, it's impossible. There are a lot of things that can hinder your progress and you need to stay committed in spite of them.&lt;/p&gt;

&lt;p&gt;So how do you keep yourself from procrastinating or altogether giving up? I'm going to share a few ways to help you maintain your streak and make progress every day.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Share your journey on the web
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aSgdfiuM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jv1gi5p2j01su1xjubkv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aSgdfiuM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jv1gi5p2j01su1xjubkv.png" alt="Alt Text" title="Social media"&gt;&lt;/a&gt;&lt;br&gt;
If you're all alone on your journey with nobody to answer to, chances are you wouldn't care if you finish your assignment today or meet your daily goals. &lt;/p&gt;

&lt;p&gt;But if you share your journey to the world you'd feel accountable to them. It would push you to reach your goals, either short-term or long-term. &lt;/p&gt;

&lt;p&gt;One of the best ways is to follow the &lt;strong&gt;#100DaysOfCode&lt;/strong&gt; challenge on Twitter. The goal is to code for at least one hour every day for the next 100 days and share your progress with the twitter community. This is helpful because the dev community will share their views and suggestions too which will keep you on the right track.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Pair programming
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FP6Z2T75--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5xa286qua0fj4akdzwx2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FP6Z2T75--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5xa286qua0fj4akdzwx2.png" alt="Alt Text" title="Pair programming"&gt;&lt;/a&gt;&lt;br&gt;
If you feel you're not ready to share with the whole world just yet, you can start small and find a code buddy. It's a great way to learn as you both stay accountable to each other's progress i.e. pair programming.&lt;/p&gt;

&lt;p&gt;Pair programming is a technique where two developers collectively code to find solutions to different coding problems.&lt;br&gt;
There are many advantages to pair programming&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You make sure your code is less prone to errors&lt;/li&gt;
&lt;li&gt;You learn interpersonal skills and how to interact with other people&lt;/li&gt;
&lt;li&gt;You learn from each other.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Get inspired
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qErdkwwa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/atm2r00i82dg36h1xzjj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qErdkwwa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/atm2r00i82dg36h1xzjj.png" alt="Alt Text" title="Reading"&gt;&lt;/a&gt;&lt;br&gt;
If you're really demotivated, I recommend reading about other people's journeys. How they became something from nothing. They could be an inspiration to you and you can learn from them.&lt;/p&gt;

&lt;p&gt;Twitter and Linkedin are the best sources to connect with such people. You could follow their advice and ask them any questions that you have. &lt;/p&gt;

&lt;h2&gt;
  
  
  4. Taking breaks
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SW4Z3gpK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5wyr01qvi97mg93x3fjz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SW4Z3gpK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5wyr01qvi97mg93x3fjz.png" alt="Alt Text" title="Chilling"&gt;&lt;/a&gt;&lt;br&gt;
The main reason why people get demotivated is because they think that they need to be coding 24/7. Having this mindset can make coding feel like a daunting task and it instantly flips the switch off. &lt;/p&gt;

&lt;p&gt;The mind can only take so much. You &lt;strong&gt;cannot&lt;/strong&gt; master everything in 1 day or 1 month or 1 year. Without resting your mind it's impossible to make progress and you can easily burn out. &lt;/p&gt;

&lt;p&gt;Instead, take breaks. By break, I mean &lt;strong&gt;don't think about code&lt;/strong&gt;. Go for a walk. Take a trip. Take the weekend off. Read a book. This refreshes your mind and also gives you new ideas to implement into your project. &lt;/p&gt;

&lt;h2&gt;
  
  
  5. Remove all distractions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L18BRoU4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6v2nv3dme26qwpiupnms.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L18BRoU4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6v2nv3dme26qwpiupnms.png" alt="Alt Text" title="Isolate yourself"&gt;&lt;/a&gt;&lt;br&gt;
The most important thing needed to train your brain to stay motivated is &lt;strong&gt;FOCUS&lt;/strong&gt;. If you lose focus, you lose interest, you procrastinate. How do you lose focus? &lt;strong&gt;DISTRACTIONS&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;So find a way to avoid all these distractions. Find a quiet place and turn off your phone while you're working. You can give yourself a few minutes break in the middle and then tend to those distractions.&lt;/p&gt;




&lt;p&gt;Thank you very much for reading. I hope this helps you in your journey like it has helped me. Happy coding!&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>What is short-circuit evaluation?</title>
      <dc:creator>nehabharati</dc:creator>
      <pubDate>Wed, 29 Apr 2020 16:16:33 +0000</pubDate>
      <link>https://dev.to/nehabharati/what-is-short-circuit-evaluation-741</link>
      <guid>https://dev.to/nehabharati/what-is-short-circuit-evaluation-741</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;We all know about the different kinds of operators in Javascript. There's arithmetic, logical, relational, unary, ternary and so on. We also know what they do and when they should be used. Here I'm going to discuss some peculiar conditions using a few of these operators to see how they behave with other data types and more importantly about &lt;strong&gt;short-circuit evaluation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;All logical expressions evaluate from left to right. The logical operators &lt;strong&gt;&amp;amp;&amp;amp;&lt;/strong&gt; and &lt;strong&gt;||&lt;/strong&gt; behave differently when dealing with values of different types. &lt;/p&gt;

&lt;h4&gt;
  
  
  &amp;amp;&amp;amp; operator
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;When the value to the left of the &lt;strong&gt;and&lt;/strong&gt; operator is evaluated to false, the condition returns false&lt;/li&gt;
&lt;li&gt;When the value to the left of the &lt;strong&gt;and&lt;/strong&gt; operator is evaluated to true, it checks if the value to the right is true or false and accordingly provides a result.
&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="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="kc"&gt;NaN&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//NaN&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="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//0&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="kc"&gt;NaN&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//NaN&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="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//null&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="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//NaN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; 0, -0, NaN, null, undefined and ""(empty string) are considered as false in Javascript. &lt;/p&gt;

&lt;h4&gt;
  
  
  || operator
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;or&lt;/strong&gt; operator works the other way around.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the value to the left of the &lt;strong&gt;or&lt;/strong&gt; operator evaluates to true, the operation returns true.&lt;/li&gt;
&lt;li&gt;When the value to the left of the &lt;strong&gt;or&lt;/strong&gt; operator is evaluated to false, it checks if the value to the right is true or false and accordingly provides a result.
&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="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="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//user&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="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//user&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;i&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;u&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//i&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code shows an interesting way &lt;strong&gt;or&lt;/strong&gt; works. The first value that evaluates to true is returned. &lt;br&gt;
The cases seen till now are all due to &lt;strong&gt;short-circuit evaluation&lt;/strong&gt;. You can read more about it &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Relational Operators
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&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="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is how a typical relational operator(&amp;lt;,&amp;gt;,&amp;gt;=,&amp;lt;=, etc) works.&lt;br&gt;
But what if we were to compare other data types like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;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;ant&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//false&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;Ant&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Strings are compared from left to right. The ASCII representation of strings can be found &lt;a href="https://www.w3schools.com/charsets/ref_html_ascii.asp"&gt;here&lt;/a&gt;. Lowercase letters are always greater than uppercase letters. So the code above is valid. &lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Short-circuit evaluation handles logical operation with different data types&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;and&lt;/strong&gt; operator behaves in such a way that it returns the value which evaluates to false&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;or&lt;/strong&gt; operator behaves in such a way that it returns the value which evaluates to true&lt;/li&gt;
&lt;li&gt;Strings are compared from left to right depending on their ASCII value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it for this article. Hope you liked it and please leave your comments below. :)&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Learn all about null,undefined and NaN</title>
      <dc:creator>nehabharati</dc:creator>
      <pubDate>Sun, 26 Apr 2020 12:19:04 +0000</pubDate>
      <link>https://dev.to/nehabharati/learn-all-about-null-undefined-and-nan-7hp</link>
      <guid>https://dev.to/nehabharati/learn-all-about-null-undefined-and-nan-7hp</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;We all come across null, undefined and NaN at some point in our coding journey. As a beginner, I'd always wanted to know how and why these &lt;em&gt;special&lt;/em&gt; values behave the way they do. So I'm going to illustrate just that in this article.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is null?
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Null&lt;/strong&gt; represents an empty value and carry no &lt;strong&gt;meaningful information&lt;/strong&gt;.&lt;br&gt;
If you use the &lt;em&gt;typeof&lt;/em&gt; operator on null, it shows that null is an object. You can read all about it over &lt;a href="https://josephkhan.me/javascript-undefined-vs-null/"&gt;here.&lt;/a&gt; In fact, null is one of the primitive values in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;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;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;   
&lt;span class="c1"&gt;//object&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  What is undefined?
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Undefined&lt;/strong&gt; represents any value that has not been defined anywhere in the program. &lt;br&gt;
If any variable or operation isn't able to produce a meaningful value, it returns undefined.&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="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;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="mi"&gt;2&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;p&gt;In the above example, there is no meaningful value for a[2] because it doesn't exist, so it returns &lt;strong&gt;undefined&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is NaN?
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;NaN&lt;/strong&gt; stands for &lt;em&gt;Not a Number&lt;/em&gt;. You get this value when you try to do some operation that can't yield a meaningful result. If you use the &lt;em&gt;typeof&lt;/em&gt; operator on NaN, it shows it is a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;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="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//NaN&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;five&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//NaN&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;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; 
&lt;span class="c1"&gt;//number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Behavior of null,undefined,NaN
&lt;/h2&gt;

&lt;p&gt;Let's have a look at how these values behave with each other, and why. &lt;/p&gt;

&lt;h4&gt;
  
  
  null and undefined
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="kc"&gt;undefined&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//false&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="kc"&gt;undefined&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//false&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="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//false&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="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;null and undefined return false when compared with any value. Or does it? Let's take a look.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;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="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="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="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="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before going into the explanation, let's take a look at how "==" and "===" work.&lt;br&gt;
"==" performs a loose equality operation between its operands and does &lt;strong&gt;type coercion&lt;/strong&gt;. &lt;br&gt;
This means that if you use "==" between two values of different types, JavaScript tries to convert one operand's type into the other's to provide a result.&lt;/p&gt;

&lt;p&gt;Whereas "===" performs a strict equality and does not try to convert the type of either value. It checks if the &lt;strong&gt;type of the values are the same&lt;/strong&gt;. If not it returns false.&lt;/p&gt;

&lt;p&gt;Now let's get back to the code. Let's look at the two cases.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;==&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;null and undefined are both falsy values and that is why it returns true in the first line. Also == operator needs its operands to contain some value. Since null and undefined don't contain any value, it returns true.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;===&lt;/strong&gt; &lt;br&gt;
  Since null and undefined are of different types, it returns false.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So null and undefined return true only when they're &lt;strong&gt;loosely compared with each other.&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  NaN
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="kc"&gt;NaN&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;NaN is in itself the result of a nonsensical computation, so equating it with any other nonsensical computation will return false. This is the only value in JavaScript that isn't equal to itself&lt;/p&gt;

&lt;p&gt;Let's make it a little interesting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;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="o"&gt;!!&lt;/span&gt;&lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//false&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="o"&gt;!&lt;/span&gt;&lt;span class="kc"&gt;NaN&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="kc"&gt;NaN&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   
&lt;span class="c1"&gt;//false &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="kc"&gt;NaN&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    
&lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since NaN is a falsy value !NaN returns true.&lt;br&gt;
NaN is not equal to any value. It always returns false.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;null and undefined are values that contain nothing.&lt;/li&gt;
&lt;li&gt;null and undefined are &lt;em&gt;loosely&lt;/em&gt; equal to each other but are &lt;em&gt;strictly&lt;/em&gt; not equal to each other.&lt;/li&gt;
&lt;li&gt;NaN is a result of nonsensical computation which cannot produce a meaningful result.&lt;/li&gt;
&lt;li&gt;NaN is the only value which isn't equal to itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this clears some of your doubts about these special values. And I hope you enjoyed reading this! &lt;/p&gt;

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