<?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: Mirza Mohibul Hasan</title>
    <description>The latest articles on DEV Community by Mirza Mohibul Hasan (@mirzaree).</description>
    <link>https://dev.to/mirzaree</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%2F1419554%2F188f8516-4180-46f6-b99a-4fae5b4a99f2.jpeg</url>
      <title>DEV Community: Mirza Mohibul Hasan</title>
      <link>https://dev.to/mirzaree</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mirzaree"/>
    <language>en</language>
    <item>
      <title>Why JavaScript's "NaN" Sucks😛</title>
      <dc:creator>Mirza Mohibul Hasan</dc:creator>
      <pubDate>Thu, 11 Apr 2024 18:01:46 +0000</pubDate>
      <link>https://dev.to/mirzaree/why-javascripts-nan-sucks-5en0</link>
      <guid>https://dev.to/mirzaree/why-javascripts-nan-sucks-5en0</guid>
      <description>&lt;p&gt;&lt;strong&gt;NaN&lt;/strong&gt; is a global property in JavaScript which represents a value that is "Not a Number". Despite its name, NaN is still considered a numeric data type in JavaScript. If you check the data type of NaN using the typeof operator, you'll find that it returns "number".&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 NaN); // number
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When comparing NaN using equality operators (== or ===), you may encounter a confusing behavior: NaN is not equal to itself. That means NaN == NaN and NaN === NaN both return false.&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(NaN == NaN); // false
console.log(NaN === NaN); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you ever need to compare NaN values, what do you do? 😛&lt;br&gt;
You have two solutions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use the isNaN() function.&lt;/li&gt;
&lt;li&gt;Use the Number.isNaN() method.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Today, let's learn how to use isNaN(). This function takes a value as an argument. If the value is NaN, it returns true; otherwise, it returns false. You don't need to manually check if a value is NaN. JavaScript handles it automatically. Before performing any automatic conversions, JavaScript tries to convert the value using the Number() constructor function.&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(Number(10)); // 10
console.log(Number('Hello')); // NaN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Number() constructor function tries to convert the argument into a number. If successful, it returns the number; otherwise, it returns NaN.&lt;/p&gt;

&lt;p&gt;Now, let's see isNaN() in action:&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(isNaN(10)); // false
console.log(isNaN('Hello')); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript can be quite confusing, and one tricky aspect is NaN (Not a Number). Understanding its concept can help you easily solve related problems 😎.&lt;/p&gt;

&lt;p&gt;Feel free to run the following examples to better understand:&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(Number(10)); // 10
console.log(Number('Hello')); // NaN
console.log(Number('5')); // 5
console.log(Number(NaN)); // NaN
console.log(Number('NaN')); // NaN
console.log(Number(null)); // 0
console.log(Number(undefined)); // NaN
console.log(Number({})); // NaN
console.log(Number([])); // 0
console.log(Number('123ABC')); // NaN
console.log(Number('')); // 0
console.log(Number(true)) // 1
console.log(Number(false)) // 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it for today! If you have any confusion or questions, feel free to ask in the comments below 😎😎&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>isnan</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
