<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: The parseInt gotcha</title>
	<atom:link href="http://ajaxian.com/archives/the-parseint-gotcha/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/the-parseint-gotcha</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 17 May 2012 07:43:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: peller</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261396</link>
		<dc:creator>peller</dc:creator>
		<pubDate>Fri, 15 Feb 2008 17:15:14 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261396</guid>
		<description>@sphivo: wow, that article is a gem.  How interesting that coercion takes hex strings but not octal.  Plenty of gotchas with either method, I guess.</description>
		<content:encoded><![CDATA[<p>@sphivo: wow, that article is a gem.  How interesting that coercion takes hex strings but not octal.  Plenty of gotchas with either method, I guess.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peller</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261395</link>
		<dc:creator>peller</dc:creator>
		<pubDate>Fri, 15 Feb 2008 17:03:42 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261395</guid>
		<description>@MarkBirbeck: certainly no hatred intended on my part. I hope my comment wasn&#039;t read as anything but constructive criticism.  And yes, you give another very good reason why parseInt() is usually overkill and better replaced by coercion, IMO, unless you are doing it specifically because you want the behavior of parsing only the number portion.</description>
		<content:encoded><![CDATA[<p>@MarkBirbeck: certainly no hatred intended on my part. I hope my comment wasn&#8217;t read as anything but constructive criticism.  And yes, you give another very good reason why parseInt() is usually overkill and better replaced by coercion, IMO, unless you are doing it specifically because you want the behavior of parsing only the number portion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p01</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261356</link>
		<dc:creator>p01</dc:creator>
		<pubDate>Wed, 13 Feb 2008 21:01:09 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261356</guid>
		<description>To ease the mood, here is another potential gotcha: per ECMAscript 262-3 specification, &lt;em&gt;Array.prototype.sort( [compareFunction] )&lt;/em&gt; is not necessary stable, and therefore should not be assumed to be stable.</description>
		<content:encoded><![CDATA[<p>To ease the mood, here is another potential gotcha: per ECMAscript 262-3 specification, <em>Array.prototype.sort( [compareFunction] )</em> is not necessary stable, and therefore should not be assumed to be stable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p01</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261355</link>
		<dc:creator>p01</dc:creator>
		<pubDate>Wed, 13 Feb 2008 20:33:16 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261355</guid>
		<description>&lt;strong&gt;MarkBirbeck:&lt;/strong&gt; Fair enough. If only the difference of time spent commenting on and stumbling on that parseInt() behavior and writting a blog post about it wasn&#039;t so big.

&lt;strong&gt;FrankManno:&lt;/strong&gt; I don&#039;t see hatred in the comments. Harshness yes but no hatred.

Beside there are thousands of results when searching for &lt;em&gt;parseInt 08&lt;/em&gt; on the net.</description>
		<content:encoded><![CDATA[<p><strong>MarkBirbeck:</strong> Fair enough. If only the difference of time spent commenting on and stumbling on that parseInt() behavior and writting a blog post about it wasn&#8217;t so big.</p>
<p><strong>FrankManno:</strong> I don&#8217;t see hatred in the comments. Harshness yes but no hatred.</p>
<p>Beside there are thousands of results when searching for <em>parseInt 08</em> on the net.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FrankManno</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261343</link>
		<dc:creator>FrankManno</dc:creator>
		<pubDate>Wed, 13 Feb 2008 15:33:59 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261343</guid>
		<description>I agree with MarkBirbeck on this one... Why the harshness?  Since when are we all above &quot;learning&quot;?!  This post may in fact help quite a few people who may be scratching their heads as to why parseInt doesn&#039;t behave as expected.

Give the hating a break already!</description>
		<content:encoded><![CDATA[<p>I agree with MarkBirbeck on this one&#8230; Why the harshness?  Since when are we all above &#8220;learning&#8221;?!  This post may in fact help quite a few people who may be scratching their heads as to why parseInt doesn&#8217;t behave as expected.</p>
<p>Give the hating a break already!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MarkBirbeck</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261333</link>
		<dc:creator>MarkBirbeck</dc:creator>
		<pubDate>Wed, 13 Feb 2008 11:52:38 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261333</guid>
		<description>Wow...give the guy a break! He didn&#039;t ask Ajaxian to make out this was some kind of major story. (Ajaxian has a habit of taking the most mundane stuff and giving it a high profile.)

And also, some respondents might do well to follow their own advice and read the spec; on the one hand we&#039;re saying Guyon should read the spec, and in the same breath some people question why &lt;code&gt;parseInt(&quot;08&quot;)&lt;/code&gt; returns &lt;code&gt;0&lt;/code&gt; instead of &lt;code&gt;NaN&lt;/code&gt;, proving that we can all overlook things, not just Guyon.

The answer, for those who understandably don&#039;t want to wade through the specs (what are blogs for, after all), is that &lt;code&gt;parseInt&lt;/code&gt; and related functions parse as much as they can from a string and then stop. So to illustrate, &lt;code&gt;parseInt(&quot;23 days&quot;, 10)&lt;/code&gt; will return &lt;code&gt;23&lt;/code&gt;, and &lt;strong&gt;not&lt;/strong&gt; &lt;code&gt;Nan&lt;/code&gt;, because it will find as many base 10 numbers as it can before stopping.

This means that the example of &lt;code&gt;parseInt(&quot;08&quot;)&lt;/code&gt; might as well be &lt;code&gt;parseInt(&quot;0banana&quot;)&lt;/code&gt; for all that it means in octal--the answer is correctly zero.

Mark</description>
		<content:encoded><![CDATA[<p>Wow&#8230;give the guy a break! He didn&#8217;t ask Ajaxian to make out this was some kind of major story. (Ajaxian has a habit of taking the most mundane stuff and giving it a high profile.)</p>
<p>And also, some respondents might do well to follow their own advice and read the spec; on the one hand we&#8217;re saying Guyon should read the spec, and in the same breath some people question why <code>parseInt("08")</code> returns <code>0</code> instead of <code>NaN</code>, proving that we can all overlook things, not just Guyon.</p>
<p>The answer, for those who understandably don&#8217;t want to wade through the specs (what are blogs for, after all), is that <code>parseInt</code> and related functions parse as much as they can from a string and then stop. So to illustrate, <code>parseInt("23 days", 10)</code> will return <code>23</code>, and <strong>not</strong> <code>Nan</code>, because it will find as many base 10 numbers as it can before stopping.</p>
<p>This means that the example of <code>parseInt("08")</code> might as well be <code>parseInt("0banana")</code> for all that it means in octal&#8211;the answer is correctly zero.</p>
<p>Mark</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kcisoul</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261331</link>
		<dc:creator>kcisoul</dc:creator>
		<pubDate>Wed, 13 Feb 2008 01:43:23 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261331</guid>
		<description>I prefer this &quot;String.prototype.parseInt=function(){return parseInt(this,10)}&quot;</description>
		<content:encoded><![CDATA[<p>I prefer this &#8220;String.prototype.parseInt=function(){return parseInt(this,10)}&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cdude</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261326</link>
		<dc:creator>cdude</dc:creator>
		<pubDate>Tue, 12 Feb 2008 22:36:15 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261326</guid>
		<description>aww, if i had known ajaxian would accept any submission I would have submitted my discovery of mozilla&#039;s setTimeout&#039;s extra parameter (the lateness) long ago.</description>
		<content:encoded><![CDATA[<p>aww, if i had known ajaxian would accept any submission I would have submitted my discovery of mozilla&#8217;s setTimeout&#8217;s extra parameter (the lateness) long ago.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p01</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261324</link>
		<dc:creator>p01</dc:creator>
		<pubDate>Tue, 12 Feb 2008 21:05:12 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261324</guid>
		<description>Sorry Tim, I lost touch with reality when I saw someone actually blogging his revelation about parseInt(). Indeed parseInt( &#039;08&#039; ); should return NaN since 08 is not a valid octal number. :p</description>
		<content:encoded><![CDATA[<p>Sorry Tim, I lost touch with reality when I saw someone actually blogging his revelation about parseInt(). Indeed parseInt( &#8217;08&#8242; ); should return NaN since 08 is not a valid octal number. :p</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sphivo</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261322</link>
		<dc:creator>sphivo</dc:creator>
		<pubDate>Tue, 12 Feb 2008 19:23:47 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261322</guid>
		<description>Just a FYI, the snippet I posted to the gumuz&#039;s blog using Prototype was just an example to show how the + operator responded to a list of date-like base-10 decimal strings.  Obviously, there&#039;s nothing Prototype-specific about the + operator.

You can read about it here: &lt;a href=&quot;http://www.jibbering.com/faq/faq_notes/type_convert.html#tcNumber&quot; rel=&quot;nofollow&quot;&gt;Javascript Type-Conversion&lt;/a&gt;.

- Mike Owens</description>
		<content:encoded><![CDATA[<p>Just a FYI, the snippet I posted to the gumuz&#8217;s blog using Prototype was just an example to show how the + operator responded to a list of date-like base-10 decimal strings.  Obviously, there&#8217;s nothing Prototype-specific about the + operator.</p>
<p>You can read about it here: <a href="http://www.jibbering.com/faq/faq_notes/type_convert.html#tcNumber" rel="nofollow">Javascript Type-Conversion</a>.</p>
<p>- Mike Owens</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: j4606</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261321</link>
		<dc:creator>j4606</dc:creator>
		<pubDate>Tue, 12 Feb 2008 18:36:22 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261321</guid>
		<description>But it worked yesterday? unfortunately the only thing that didn&#039;t work was your ability to read the specs.</description>
		<content:encoded><![CDATA[<p>But it worked yesterday? unfortunately the only thing that didn&#8217;t work was your ability to read the specs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peller</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261315</link>
		<dc:creator>peller</dc:creator>
		<pubDate>Tue, 12 Feb 2008 16:49:45 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261315</guid>
		<description>umm... Javascript is perfectly natural here, to the point where you typically shouldn&#039;t resort to using parseInt!  String-&gt;number coercion was the right solution all along, as the author discovered, and has exactly the behavior he was looking for -- whether he used the plus trick or the explicit Number constructor or whatever.  No need for fancy toolkits here until you need to iterate.  He just shouldn&#039;t have been using parseInt in the first place, which does very specific things which are also in line with the language, but obviously a bit more technical in nature (you might notice that number literals also respect the ohhh prefix!)</description>
		<content:encoded><![CDATA[<p>umm&#8230; Javascript is perfectly natural here, to the point where you typically shouldn&#8217;t resort to using parseInt!  String-&gt;number coercion was the right solution all along, as the author discovered, and has exactly the behavior he was looking for &#8212; whether he used the plus trick or the explicit Number constructor or whatever.  No need for fancy toolkits here until you need to iterate.  He just shouldn&#8217;t have been using parseInt in the first place, which does very specific things which are also in line with the language, but obviously a bit more technical in nature (you might notice that number literals also respect the ohhh prefix!)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sebcreme</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261314</link>
		<dc:creator>sebcreme</dc:creator>
		<pubDate>Tue, 12 Feb 2008 15:50:57 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261314</guid>
		<description>Considering javascript should be always as natural as possible to use why are we bother with plain old rules like &quot;octal are starting with 0&quot; ? (which may be an old International Business Machine hack)
Should not be a real ohhh ? 
like o12 or 12o

Everyone can live better with the ohhh !</description>
		<content:encoded><![CDATA[<p>Considering javascript should be always as natural as possible to use why are we bother with plain old rules like &#8220;octal are starting with 0&#8243; ? (which may be an old International Business Machine hack)<br />
Should not be a real ohhh ?<br />
like o12 or 12o</p>
<p>Everyone can live better with the ohhh !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jaredmellentine</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261313</link>
		<dc:creator>jaredmellentine</dc:creator>
		<pubDate>Tue, 12 Feb 2008 15:25:11 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261313</guid>
		<description>Dion:

You should probably run your code through JSLint (&lt;a href=&quot;http://jslint.com/&quot; rel=&quot;nofollow&quot;&gt;http://jslint.com/&lt;/a&gt;).  It would have thrown an error about the radix missing.</description>
		<content:encoded><![CDATA[<p>Dion:</p>
<p>You should probably run your code through JSLint (<a href="http://jslint.com/" rel="nofollow">http://jslint.com/</a>).  It would have thrown an error about the radix missing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jdalton</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261312</link>
		<dc:creator>jdalton</dc:creator>
		<pubDate>Tue, 12 Feb 2008 14:43:42 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261312</guid>
		<description>His work around is pretty nice to, I have always used parseInt(foo, 10);</description>
		<content:encoded><![CDATA[<p>His work around is pretty nice to, I have always used parseInt(foo, 10);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Diodeus</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261311</link>
		<dc:creator>Diodeus</dc:creator>
		<pubDate>Tue, 12 Feb 2008 13:59:36 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261311</guid>
		<description>The reason it COULD return NAN is because 08 is the prefix indicating that the number *following* it is in octal. Since there is *nothing* following it NAN would make sense.</description>
		<content:encoded><![CDATA[<p>The reason it COULD return NAN is because 08 is the prefix indicating that the number *following* it is in octal. Since there is *nothing* following it NAN would make sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joeri</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261310</link>
		<dc:creator>Joeri</dc:creator>
		<pubDate>Tue, 12 Feb 2008 13:35:48 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261310</guid>
		<description>NaN is a well-defined concept from floating point arithmetic. Since parseInt is supposed to return an integer, it therefore shouldn&#039;t return NaN.</description>
		<content:encoded><![CDATA[<p>NaN is a well-defined concept from floating point arithmetic. Since parseInt is supposed to return an integer, it therefore shouldn&#8217;t return NaN.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Cooijmans</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261308</link>
		<dc:creator>Tim Cooijmans</dc:creator>
		<pubDate>Tue, 12 Feb 2008 13:08:45 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261308</guid>
		<description>Mathieu: I don&#039;t see how NaN would be more ludicrous than 0 or 10.  Other than that, yes, passing the radix argument is _the_ solution.</description>
		<content:encoded><![CDATA[<p>Mathieu: I don&#8217;t see how NaN would be more ludicrous than 0 or 10.  Other than that, yes, passing the radix argument is _the_ solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wortwart</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261307</link>
		<dc:creator>wortwart</dc:creator>
		<pubDate>Tue, 12 Feb 2008 13:05:41 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261307</guid>
		<description>I know, cross-browser testing is out ... I checked it on Firefox 2, IE7, Safari 3 Beta and Opera 9, all on Windows. They all returned 0, except Opera. Adding 10 as 2nd parameter to parseInt() returned the correct result in all 4 browsers.</description>
		<content:encoded><![CDATA[<p>I know, cross-browser testing is out &#8230; I checked it on Firefox 2, IE7, Safari 3 Beta and Opera 9, all on Windows. They all returned 0, except Opera. Adding 10 as 2nd parameter to parseInt() returned the correct result in all 4 browsers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ingdir</title>
		<link>http://ajaxian.com/archives/the-parseint-gotcha/comment-page-1#comment-261302</link>
		<dc:creator>ingdir</dc:creator>
		<pubDate>Tue, 12 Feb 2008 12:15:11 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3323#comment-261302</guid>
		<description>Thank you. The simplest things are sometimes the most difficult ones to remember.</description>
		<content:encoded><![CDATA[<p>Thank you. The simplest things are sometimes the most difficult ones to remember.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

