<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Where&#039;s Walden? &#187; Infinity</title>
	<atom:link href="http://whereswalden.com/tag/infinity/feed/" rel="self" type="application/rss+xml" />
	<link>http://whereswalden.com</link>
	<description>Mozilla, politics, economics, law, backpacking, cycling, and other random desiderata</description>
	<lastBuildDate>Thu, 03 May 2012 09:13:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>More ES5 backwards-incompatible changes: the global properties undefined, NaN, and Infinity are now immutable</title>
		<link>http://whereswalden.com/2010/01/12/more-es5-backwards-incompatible-changes-the-global-properties-undefined-nan-and-infinity-are-now-immutable/</link>
		<comments>http://whereswalden.com/2010/01/12/more-es5-backwards-incompatible-changes-the-global-properties-undefined-nan-and-infinity-are-now-immutable/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 19:41:44 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[ecma-262]]></category>
		<category><![CDATA[ecmascript]]></category>
		<category><![CDATA[es5]]></category>
		<category><![CDATA[Infinity]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[NaN]]></category>
		<category><![CDATA[spidermonkey]]></category>
		<category><![CDATA[undefined]]></category>

		<guid isPermaLink="false">http://whereswalden.com/?p=1244</guid>
		<description><![CDATA[(preemptive clarification: coming in Firefox 3.7 and not Firefox 3.6, which is to say, a good half year away from now rather than Real Soon Now) JavaScript and the undefined, Infinity, and NaN &#8220;keywords&#8221; Consider the following JavaScript program: what do you think it does? print("undefined before: " + undefined); undefined = 17; print("undefined after: [...]]]></description>
			<content:encoded><![CDATA[<p>(preemptive clarification: coming in <strong>Firefox 3.7</strong> and <em>not</em> Firefox 3.6, which is to say, a good half year away from now rather than Real Soon Now)</p>
<h2>JavaScript and the <code>undefined</code>, <code>Infinity</code>, and <code>NaN</code> &#8220;keywords&#8221;</h2>
<p>Consider the following JavaScript program: what do you think it does?</p>
<pre class="code" data-language="javascript">
print("undefined before: " + undefined);
undefined = 17;
print("undefined after:  " + undefined);
</pre>
<p>The above program will print this output:</p>
<pre class="code" data-language="javascript">
undefined before: undefined
undefined after:  17
</pre>
<h2>Surely you can&#8217;t be serious!</h2>
<p>A sane person might think that this program isn&#8217;t even a program.  Doesn&#8217;t <code>undefined</code> always refer to the primitive value <code>undefined</code>?  After all, this &#8220;program&#8221; isn&#8217;t one, nor would be the same one for <code>true</code> or <code>false</code>, <span lang="la">mutatis mutandis</span>:</p>
<pre class="code" data-language="javascript">
print("null before: " + null);
null = 17; // !!! NullLiteral is not a LeftHandSideExpression
print("null after:  " + null);
</pre>
<h2>I am serious&#8230;and don&#8217;t call me Shirley</h2>
<p>Curiously, the program that assigns to <code>undefined</code> is a valid JavaScript program, but programs that assign to <code>null</code>, <code>true</code>, and <code>false</code> are not.  Why not?  The latter are all <dfn>keywords</dfn> with intrinsic meaning within the language; <code>undefined</code>, on the other hand, is just a normal property of the global object.  According to ECMA-262 3rd edition, if you assign a different value to <code>undefined</code>, that different value becomes the new value of <code>undefined</code>.</p>
<p>This is a clear botch in <abbr title="ECMA-262 3rd edition">ES3</abbr>.  <code>undefined</code> should have been a keyword in JavaScript from the beginning; similarly, the global properties <code>Infinity</code> and <code>NaN</code> probably should have been keywords as well (or perhaps the properties should not have existed, given that <code>Math.Infinity</code> and <code>Math.NaN</code> exist and are immutable).  ECMA-262 5th edition doesn&#8217;t quite go so far as to change these three properties into keywords due to backwards compatibility concerns (making that change would be guaranteed to break any programs that even tried to assign to those names, regardless whether the program relied on that assignment for correctness).  Instead, it changes these properties to be read-only, in the same way that the various numeric properties on the <code>Math</code> object are read-only.  Assigning to these properties in <abbr title="ECMA-262 5th edition">ES5</abbr> won&#8217;t do anything (unless you opt into strict mode, in which case a <code>TypeError</code> exception will be thrown after we fix <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=537873">bug 537873</a>), but at least it won&#8217;t <em>definitely</em> and <em>completely</em> break existing programs that relied on this.</p>
<p>We&#8217;ve made this change in SpiderMonkey, and it is now in trunk builds of Firefox, slated for the eventual <strong>Firefox 3.7</strong> release.  Download a nightly build from <a href="http://nightly.mozilla.org/">nightly.mozilla.org</a> and test out the change for yourself (<a href="http://support.mozilla.com/en-US/kb/Managing+profiles">use the profile manager</a> if you want to keep your current Firefox settings and install untouched).  This change should have no effect on the vast, vast majority of web developers who don&#8217;t try to change the values of these properties; as for the [civility and my religion require I redact this description] developers who <em>did</em> change the value of the global <code>undefined</code>, <code>NaN</code>, or <code>Infinity</code> properties, well&#8230;<a href="http://www.youtube.com/watch?v=pDRN3umyXTk">you had it coming</a>.</p>
<h2>The bottom line</h2>
<p><strong>The global properties <code>undefined</code>, <code>Infinity</code>, and <code>NaN</code> will be read-only and immutable in Firefox 3.7</strong>.  Assigning to these properties will do nothing (except in strict mode where a <code>TypeError</code> exception will be thrown once we fix <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=537873">a bug</a>) rather than changing their values.  This shouldn&#8217;t break the vast, vast, vast majority of scripts out there &mdash; but there&#8217;s no way to guarantee it will break no one, so we think it&#8217;s worth announcing this backwards-incompatible change as proactively as possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://whereswalden.com/2010/01/12/more-es5-backwards-incompatible-changes-the-global-properties-undefined-nan-and-infinity-are-now-immutable/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

