<?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: Parth</title>
    <description>The latest articles on DEV Community by Parth (@parthctrl).</description>
    <link>https://dev.to/parthctrl</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%2F4026306%2F046cb9f7-8fba-40a0-a536-b37f02853120.jpg</url>
      <title>DEV Community: Parth</title>
      <link>https://dev.to/parthctrl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/parthctrl"/>
    <language>en</language>
    <item>
      <title>typeof null is "object" — a bug from 1995 nobody can fix</title>
      <dc:creator>Parth</dc:creator>
      <pubDate>Sun, 12 Jul 2026 19:28:22 +0000</pubDate>
      <link>https://dev.to/parthctrl/typeof-null-is-object-a-bug-from-1995-nobody-can-fix-268g</link>
      <guid>https://dev.to/parthctrl/typeof-null-is-object-a-bug-from-1995-nobody-can-fix-268g</guid>
      <description>&lt;p&gt;I'm learning JavaScript. A few weeks in, I ran this line:&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="nf"&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="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;p&gt;And I stared at it for a while.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;null&lt;/code&gt; is not an object. It's the value you use to say &lt;em&gt;there is deliberately nothing here&lt;/em&gt;. It's a primitive — same family as &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt;. So why does JavaScript insist on calling it an object?&lt;/p&gt;

&lt;p&gt;I assumed I'd misunderstood something. I hadn't. It's a bug. It's been in the language since 1995, everybody knows about it, and it is never getting fixed.&lt;/p&gt;

&lt;p&gt;Here's the story, because it turned out to be the most interesting thing I've learned so far.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it came from
&lt;/h2&gt;

&lt;p&gt;JavaScript was created by Brendan Eich in about 10 days in 1995. That's not a joke — Netscape wanted a scripting language for their browser and they wanted it immediately.&lt;/p&gt;

&lt;p&gt;When you build a language that fast, you take shortcuts. One of them was how values got stored in memory. Every value carried a small &lt;strong&gt;type tag&lt;/strong&gt; — a few bits at the front saying "this is a number," "this is a string," and so on. To find out a value's type, the engine just looked at the tag.&lt;/p&gt;

&lt;p&gt;The tag for an &lt;strong&gt;object&lt;/strong&gt; was all zeros.&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;null&lt;/code&gt;? In that original implementation, &lt;code&gt;null&lt;/code&gt; was represented as a null pointer — which, on the machine, is also all zeros.&lt;/p&gt;

&lt;p&gt;So when &lt;code&gt;typeof&lt;/code&gt; looked at &lt;code&gt;null&lt;/code&gt;, it saw all zeros, checked its table, and confidently reported: &lt;strong&gt;object&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That's it. That's the whole bug. Two different things happened to look identical to the one piece of code that was supposed to tell them apart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it was never fixed
&lt;/h2&gt;

&lt;p&gt;This is the part I find genuinely interesting.&lt;/p&gt;

&lt;p&gt;Everyone figured this out pretty quickly. It's not a mystery, and it's not hard to fix — you'd just special-case &lt;code&gt;null&lt;/code&gt; in &lt;code&gt;typeof&lt;/code&gt; and be done in an afternoon.&lt;/p&gt;

&lt;p&gt;But by the time anyone got around to it, the web already existed. Thousands of sites had shipped code that ran &lt;code&gt;typeof x === "object"&lt;/code&gt; and depended on getting &lt;code&gt;true&lt;/code&gt; back for &lt;code&gt;null&lt;/code&gt;. Some of that code was checking whether a value was "object-ish." Some of it was doing something weirder. Nobody knew exactly how much of it was out there, and nobody could go and edit it.&lt;/p&gt;

&lt;p&gt;So fixing the bug would mean breaking working websites. Real ones. Pages that people were using.&lt;/p&gt;

&lt;p&gt;There was actually a proposal, years later, to make &lt;code&gt;typeof null&lt;/code&gt; return &lt;code&gt;"null"&lt;/code&gt;. It was rejected. The reasoning was blunt: it would break too much.&lt;/p&gt;

&lt;p&gt;The bug stayed. Not because it was hard to fix, but because &lt;strong&gt;the cost of fixing it was higher than the cost of living with it.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I actually took away from this
&lt;/h2&gt;

&lt;p&gt;I started out thinking this was a piece of JavaScript trivia — the kind of thing that shows up in interview questions and nowhere else.&lt;/p&gt;

&lt;p&gt;But it taught me something bigger, and it's not really about JavaScript:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Once people depend on your mistake, it stops being a mistake and becomes a feature you have to support.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's a slightly uncomfortable thought when you're a beginner writing code nobody else will ever run. But it reframed how I read old, weird, "why is it like this" corners of a language. Usually the answer isn't that the designers were careless. It's that they were fast, or early, or working with constraints that no longer exist — and then the world built on top of them before anyone could go back.&lt;/p&gt;

&lt;p&gt;Ten days in 1995. One shortcut. And &lt;code&gt;typeof null === "object"&lt;/code&gt; ever since.&lt;/p&gt;

&lt;h2&gt;
  
  
  The practical bit
&lt;/h2&gt;

&lt;p&gt;If you actually need to check for &lt;code&gt;null&lt;/code&gt;, don't use &lt;code&gt;typeof&lt;/code&gt;. Just compare directly:&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&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="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// definitely null&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if you want to know whether something is a real object, you have to rule &lt;code&gt;null&lt;/code&gt; out yourself:&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;value&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="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// an actual object&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That extra &lt;code&gt;value !== null&lt;/code&gt; is in a lot of real codebases. Now you know why it's there.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Have you ever come across a JavaScript behavior that made you stop and think, "Why does it work like that?" I'd love to hear about it in the comments.&lt;/em&gt;&lt;/p&gt;

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