<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Javascript&#8217;s null Value Has an Identity Crisis</title>
	<link>http://www.uselesspickles.com/blog/2006/06/12/javascript-null-identity-crisis/</link>
	<description>...or is it Use Less Pickles?</description>
	<pubDate>Fri, 21 Nov 2008 02:38:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.1</generator>

	<item>
		<title>by: marijn</title>
		<link>http://www.uselesspickles.com/blog/2006/06/12/javascript-null-identity-crisis/#comment-1544</link>
		<pubDate>Sat, 01 Sep 2007 14:28:46 +0000</pubDate>
		<guid>http://www.uselesspickles.com/blog/2006/06/12/javascript-null-identity-crisis/#comment-1544</guid>
					<description>As I understand it, this is basically a bug in the original Netscape JavaScript implementation that later was promoted to feature -- Microsoft had copied the behaviour in their implementation and was hestitant to break existing code.

(Things like this really suck about JS -- and as I understand it ECMAScript 4 isn't going to fix this.)</description>
		<content:encoded><![CDATA[<p>As I understand it, this is basically a bug in the original Netscape JavaScript implementation that later was promoted to feature &#8212; Microsoft had copied the behaviour in their implementation and was hestitant to break existing code.</p>
<p>(Things like this really suck about JS &#8212; and as I understand it ECMAScript 4 isn&#8217;t going to fix this.)
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: gingercamel</title>
		<link>http://www.uselesspickles.com/blog/2006/06/12/javascript-null-identity-crisis/#comment-1473</link>
		<pubDate>Wed, 13 Jun 2007 17:08:23 +0000</pubDate>
		<guid>http://www.uselesspickles.com/blog/2006/06/12/javascript-null-identity-crisis/#comment-1473</guid>
					<description>I totally agree with UP that since null is considered not to be an instance of Object, then logically null should not have a type of 'object'. In fact in Professional JavaScript for Web Developers - 2005 - (By Nicholas Zachas) it is written at page 17 (I know.. it sounds almost religious...):

&lt;i&gt;&quot;You may wonder why the typeof operator returns “object” for a value that is null.
This was actually an error in the original JavaScript implementation that was then
copied in ECMAScript. Today, it is rationalized that null is considered a placeholder
for an object, even though, technically, it is a primitive value.&quot;&lt;/i&gt;
 So I guess UP is right, it is actually an error.</description>
		<content:encoded><![CDATA[<p>I totally agree with UP that since null is considered not to be an instance of Object, then logically null should not have a type of &#8216;object&#8217;. In fact in Professional JavaScript for Web Developers - 2005 - (By Nicholas Zachas) it is written at page 17 (I know.. it sounds almost religious&#8230;):</p>
<p><i>&#8220;You may wonder why the typeof operator returns “object” for a value that is null.<br />
This was actually an error in the original JavaScript implementation that was then<br />
copied in ECMAScript. Today, it is rationalized that null is considered a placeholder<br />
for an object, even though, technically, it is a primitive value.&#8221;</i><br />
 So I guess UP is right, it is actually an error.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: UselessPickles</title>
		<link>http://www.uselesspickles.com/blog/2006/06/12/javascript-null-identity-crisis/#comment-69</link>
		<pubDate>Thu, 06 Jul 2006 05:17:24 +0000</pubDate>
		<guid>http://www.uselesspickles.com/blog/2006/06/12/javascript-null-identity-crisis/#comment-69</guid>
					<description>I agree that the browsers are acting according to standards in this situation. The problem is that the behavior creates a conflict that is a pain in the butt when programming. I agree with the behavior of the instanceof operator; null is not an instance of Object and it should not be. It is the typeof operator that I am complaining about. Since null is not an instance of Object, it makes no sense that typeof null == &quot;object&quot;. It would make more sense if typeof null == &quot;null&quot;. I can't think of any reason that the behavior of the typeof operator as defined by the standards would be desireable. I know that in other languages (specifically, Java), a null value can have a type (e.g. String myString = null;), but since Javascript is so loosly typed, null is just null (although internally to the implementation of the language it is a value of type Null, that info is not available to the end-user of the language).

btw - I think you may have left something out of your example that shows why &quot;null instanceof Object == true&quot; would be bad, because the example never tests if &quot;o instanceof Object&quot;.</description>
		<content:encoded><![CDATA[<p>I agree that the browsers are acting according to standards in this situation. The problem is that the behavior creates a conflict that is a pain in the butt when programming. I agree with the behavior of the instanceof operator; null is not an instance of Object and it should not be. It is the typeof operator that I am complaining about. Since null is not an instance of Object, it makes no sense that typeof null == &#8220;object&#8221;. It would make more sense if typeof null == &#8220;null&#8221;. I can&#8217;t think of any reason that the behavior of the typeof operator as defined by the standards would be desireable. I know that in other languages (specifically, Java), a null value can have a type (e.g. String myString = null;), but since Javascript is so loosly typed, null is just null (although internally to the implementation of the language it is a value of type Null, that info is not available to the end-user of the language).</p>
<p>btw - I think you may have left something out of your example that shows why &#8220;null instanceof Object == true&#8221; would be bad, because the example never tests if &#8220;o instanceof Object&#8221;.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: mdimitrov</title>
		<link>http://www.uselesspickles.com/blog/2006/06/12/javascript-null-identity-crisis/#comment-68</link>
		<pubDate>Wed, 05 Jul 2006 11:50:25 +0000</pubDate>
		<guid>http://www.uselesspickles.com/blog/2006/06/12/javascript-null-identity-crisis/#comment-68</guid>
					<description>The browsers act exactly as it is described in the ECMA 262 standard (http://www.ecma-international.org/publications/standards/Ecma-262.htm). 

1. Section 4.3.1 defines what a type is: A type is a set of data values.
2. Section 4.3.3 defines the Object type: An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method.
3. Section 4.3.12 defines the Null type: The type Null has exactly one value, called null.

Based on the above and the assumption that a value can belong only to one type we can conclude that &lt;code&gt;null instanceof Object&lt;/code&gt; must be &lt;code&gt;false&lt;/code&gt; because &lt;code&gt;null&lt;/code&gt; is not part of the &lt;code&gt;Object&lt;/code&gt; type (or set). If there was a native type (or object) like &lt;code&gt;Null&lt;/code&gt; then &lt;code&gt;null instanceof Null&lt;/code&gt; will be &lt;code&gt;true&lt;/code&gt;.

There are more &quot;evidences&quot; in the standard, however:

1. Section 11.4.3 defines the &lt;code&gt;typeof&lt;/code&gt; operator. It explicitly defines that &lt;code&gt;typeof null&lt;/code&gt; is &quot;object&quot;.
2. Section 11.8.6 defines the &lt;code&gt;instanceof&lt;code&gt; operator. Basicaly it says that the result is what is returned by the &lt;code&gt;[[HasInstance]]&lt;/code&gt; internal method of the right-hand operand.
3. The only standard object that implements the &lt;code&gt;[[HasInstance]]&lt;/code&gt; method is the &lt;code&gt;Function&lt;/code&gt; object. Section 15.3.5.3 defines this method. It explicitly says that if the value of the left-hand operand of the &lt;code&gt;instanceof&lt;/code&gt; operator (which was passed as an argument to this method) is &lt;code&gt;null&lt;/code&gt; then the result is &lt;code&gt;false&lt;/code&gt;.

I do see reasoning in the fact that &lt;code&gt;null&lt;/code&gt; is not instance of any object. The same is in other languages (like for example Java) where &lt;code&gt;null instanceof Object&lt;/code&gt; is also &lt;code&gt;false&lt;/code&gt;.

Let's say that you have a function that works on Number or String objects. For example:

function reverseSymbols(o)
{
    if (o instanceof Number) {
        // convert the number to string and reverse it
    } else if (o instanceof String) {
        // reverse the string
    }
}

I think it is obvious that in this case it is a good thing that &lt;code&gt;null instanceof Object&lt;/code&gt; will return &lt;code&gt;false&lt;/code&gt;.</description>
		<content:encoded><![CDATA[<p>The browsers act exactly as it is described in the ECMA 262 standard (http://www.ecma-international.org/publications/standards/Ecma-262.htm). </p>
<p>1. Section 4.3.1 defines what a type is: A type is a set of data values.<br />
2. Section 4.3.3 defines the Object type: An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method.<br />
3. Section 4.3.12 defines the Null type: The type Null has exactly one value, called null.</p>
<p>Based on the above and the assumption that a value can belong only to one type we can conclude that <code>null instanceof Object</code> must be <code>false</code> because <code>null</code> is not part of the <code>Object</code> type (or set). If there was a native type (or object) like <code>Null</code> then <code>null instanceof Null</code> will be <code>true</code>.</p>
<p>There are more &#8220;evidences&#8221; in the standard, however:</p>
<p>1. Section 11.4.3 defines the <code>typeof</code> operator. It explicitly defines that <code>typeof null</code> is &#8220;object&#8221;.<br />
2. Section 11.8.6 defines the <code>instanceof<code> operator. Basicaly it says that the result is what is returned by the <code>[[HasInstance]]</code> internal method of the right-hand operand.<br />
3. The only standard object that implements the <code>[[HasInstance]]</code> method is the <code>Function</code> object. Section 15.3.5.3 defines this method. It explicitly says that if the value of the left-hand operand of the <code>instanceof</code> operator (which was passed as an argument to this method) is <code>null</code> then the result is <code>false</code>.</p>
<p>I do see reasoning in the fact that <code>null</code> is not instance of any object. The same is in other languages (like for example Java) where <code>null instanceof Object</code> is also <code>false</code>.</p>
<p>Let&#8217;s say that you have a function that works on Number or String objects. For example:</p>
<p>function reverseSymbols(o)<br />
{<br />
    if (o instanceof Number) {<br />
        // convert the number to string and reverse it<br />
    } else if (o instanceof String) {<br />
        // reverse the string<br />
    }<br />
}</p>
<p>I think it is obvious that in this case it is a good thing that <code>null instanceof Object</code> will return <code>false</code>.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
