<?xml version="1.0" encoding="UTF-8"?> 







<rss version="2.0"  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:rss="http://backend.userland.com/rss2">
	<channel>

		<title>'null' is null or not an object</title>
		
		<link>http://wolfgang.schmidetzki.net/blog/archives/2009-11/null_is_null_or_not_an_object.int.html</link> 
		<description>'null' is null or not an object</description>
		<copyright>Wolfgang Schmidetzki</copyright>
		<generator>OpenWGA</generator>

		
		
			
		
			
		
			
		
		<lastBuildDate>14 Nov 2009 22:42:03 GMT</lastBuildDate>

	
	
		
		<item>
			<guid isPermaLink="false">8a85818e2490dba70124d7be6177565c</guid>
			<title>Trackback from BlogHouse</title>
			<link>http://wolfgang.schmidetzki.net/blog/archives/2009-11/null_is_null_or_not_an_object/anderen_geht_es_auch_so.int.html</link>
			<description>
				<![CDATA[				
				
				<h2>anderen geht es auch so</h2>

<p>Nicht nur ich rege mich in regelmäßigen Abständen über unser aller Werkzeug des Teufels, den Internet Explorer, auf. Nein es tun andere ebenso.</p>

<p>Wolfgang Schmidetzki findet passende Worte zu den Javascript Fehlermeldungen im IE:
Internet Explorer sucks...</p>

				]]>
			</description>
			<pubDate></pubDate>
			<dc:creator>BlogHouse</dc:creator>
		</item>
	
		
		<item>
			<guid isPermaLink="false">8a85818e24ea2d780124f4ae07031462</guid>
			<title>Comment from nitro2k01</title>
			<link>http://wolfgang.schmidetzki.net/blog/archives/2009-11/null_is_null_or_not_an_object/comment_from_nitro2k01_to_null_is_null_or_not_an_object.int.html</link>
			<description>
				<![CDATA[				
				
				<p>(The formatting in the above post is messed, so I'm reposting with fixed formatting. You can delete the first comment.)</p>

<p>Let me shed some light on this message. First it's important to understand what objects are in Javascript, they are hash lists, or in other words associative arrays. If you do this for example...</p>

<pre><code>var myObject = {};
myObject.property = 42;
</code></pre>

<p>...you are first creating a new object which you reference as myObject. Then you're giving that object a property named property. But this is no different from this code...</p>

<pre><code> var myObject = {};
 myObject['property'] = 42;
</code></pre>

<p>...where you're storing the property in the form of an associative array element.</p>

<p>So what about the error then? That error happens when the script tries to reference an associative array element from something that isn't an associative array. And there actually only two thing in JS that are not associative arrays, and that is the special values null and undefined. You might think that strings and numbers are also not associative arrays, but this is not the case. Even if you can't modify the properties of a number, there are still properties that can be used, most notably the function toString. For example...</p>

<pre><code> alert((42).toString())
</code></pre>

<p>...or even, using the other syntax:</p>

<pre><code> alert((42)['toString']())
</code></pre>

<p>So we're left with two things that are not associative arrays, again null and undefined, which thus will create this error. This code will trigger this error:</p>

<pre><code> alert(undefined.test);
 alert(null.test);
</code></pre>

<p>However, this code will not fail with same message:</p>

<pre><code> alert(nonExistentVariable.test);
</code></pre>

<p>It will fail already at the evalution of nonExistentVariable and complain that "nonExistentVariable is undefined". However, this code will still generate the error, because the function argument x is undefined and then you try to access an array element in it. x is undefined, so it is indeed either null or not an object.</p>

<pre><code> function test(x){
     alert(x.y);
 }
 test();
</code></pre>

<p>I hope this cleared up what this message means. Of course, this problem is secondary. The real problem is how a variable ended up being undefined or null, which probably happens because the browser doesn't have support for some particular function. The message itself exists on all browsers, but with different wording. </p>

<p>Opera has the almost as bad message: "Cannot convert undefined or null to Object" while Firefox has the much better "undefined has no properties".  </p>

				]]>
			</description>
			<pubDate></pubDate>
			<dc:creator>nitro2k01</dc:creator>
		</item>
	
		
		<item>
			<guid isPermaLink="false">8a85818e24ea2d780124f4dc367317e4</guid>
			<title>Comment from Wolfgang Schmidetzki</title>
			<link>http://wolfgang.schmidetzki.net/blog/archives/2009-11/null_is_null_or_not_an_object/comment_from_wolfgang_schmidetzki_to_null_is_null_or_not_an_object.int.html</link>
			<description>
				<![CDATA[				
				
				<p>nitro2k01: wow, what and excelent description of the origin of that kind of error message in IE-javascript.
Thanks for that.</p>

<p>However ... the message itself is not very helpfull.
What would help f. e. ist the <em>correct</em> name of the var that causes the error.</p>

<p>Calling your sample test() in IE gives the message: y is null or not an object".
That is irritating bc. the problem is "x" and not "y".</p>

<p>If you call test() in FireFox, you will get the message: "x is undefined" what is correct.</p>

<p>More badly: <br />
Change the body of your function test() to alert(x.y()) and you will get the meaningless message
"undefined is null or not an object" from IE, while FF will say "x is undefined" witch is mutch more correct and helpfull.</p>

				]]>
			</description>
			<pubDate></pubDate>
			<dc:creator>Wolfgang Schmidetzki</dc:creator>
		</item>
	
	
	</channel>
</rss>
