<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-7066219.post1426619220592737413..comments</id><updated>2007-04-30T12:59:05.423-04:00</updated><category term='Cars'/><category term='Visual Studio'/><category term='WWDC'/><category term='Mail.App'/><category term='Performance'/><category term='WarCraft'/><category term='HD'/><category term='Bug'/><category term='Misc'/><category term='UI'/><category term='RIAs'/><category term='Apple TV'/><category term='Windows'/><category term='SQLite'/><category term='SecureClient'/><category term='WebKit'/><category term='Apple'/><category term='RIA'/><category term='Halo'/><category term='Web'/><category term='ASP.NET'/><category term='Environment'/><category term='StarCraft'/><category term='Criticism'/><category term='Flash'/><category term='RSS'/><category term='FLAC'/><category term='Cocoa Touch'/><category term='iPod'/><category term='Delight'/><category term='SharpDevelop'/><category term='Beta'/><category term='Mac'/><category term='Safari'/><category term='Networking'/><category term='PC'/><category term='Marketing'/><category term='MMO'/><category term='App Store'/><category term='iPod touch'/><category term='Humor'/><category term='Mono'/><category term='MS Points'/><category term='Giants'/><category term='iOS'/><category term='ALAC'/><category term='iMac'/><category term='.NET to Cocoa'/><category term='Adobe'/><category term='HD-DVD'/><category term='Adobe Air'/><category term='Gaming'/><category term='TV'/><category term='Sony'/><category term='CSS'/><category term='Subversion'/><category term='WoW'/><category term='Images'/><category term='UX'/><category term='Xbox'/><category term='Wii'/><category term='Windows Server 2003 SP2'/><category term='XML'/><category term='Design'/><category term='Blogger'/><category term='Word'/><category term='Widgets'/><category term='Parallels'/><category term='SDK'/><category term='NT'/><category term='Development'/><category term='Tangerine Element'/><category term='Firefox'/><category term='iPhone'/><category term='MobileMe'/><category term='iTunes'/><category term='Tip'/><category term='HTML'/><category term='GarageBand'/><category term='Internet Explorer'/><category term='EVDO'/><category term='JavaScript'/><category term='Movies'/><category term='Handbrake'/><category term='Visual Studio .NET 2003'/><category term='Windows Server 2003'/><category term='Star Trek'/><category term='Interface Builder'/><category term='Windows Server 2003 SP1'/><category term='.NET'/><category term='Media'/><category term='iWork'/><category term='iTimeZone'/><category term='Reznor'/><category term='Vista'/><category term='Twitter'/><category term='Microsoft'/><category term='Blu-ray'/><category term='Robots'/><category term='PS3'/><category term='Xcode'/><category term='XP'/><category term='NIN'/><category term='SQL Server'/><category term='Visual Studio 2005'/><category term='Xbox 360'/><category term='AJAX'/><category term='PostMortem'/><category term='NDA'/><category term='GeoNames'/><category term='Annoyance'/><category term='Security'/><category term='.Mac'/><category term='Leopard'/><category term='OS X'/><category term='Politics'/><category term='VM'/><category term='Chrome'/><category term='NetNewsWire'/><category term='Mozilla'/><category term='Software Update'/><category term='Objective-C'/><category term='Nintendo'/><category term='Playstation 3'/><category term='Cloud'/><category term='HDTV'/><category term='Reviews'/><category term='Video Games'/><category term='Office'/><category term='Xbox Live'/><category term='Music'/><category term='SharePoint'/><category term='iPhone OS'/><category term='iChat'/><category term='Google'/><category term='Snow Leopard'/><category term='Blogging'/><category term='C#'/><category term='Camino'/><category term='Firebug'/><category term='Consumers'/><category term='iPhone 4'/><category term='Linux'/><category term='Cocoa'/><category term='Rentals'/><category term='iPad'/><category term='Sports'/><category term='Football'/><category term='Subscriptions'/><category term='Silverlight'/><title type='text'>Comments on Inner Exception: Tip: Make sure you declare JavaScript For loops co...</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.innerexception.com/feeds/1426619220592737413/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html'/><author><name>Dave Murdock</name><uri>http://www.blogger.com/profile/05890407802752665754</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7066219.post-5387439926276085973</id><published>2007-04-30T12:59:00.000-04:00</published><updated>2007-04-30T12:59:00.000-04:00</updated><title type='text'>It looks like the &lt;b&gt;let&lt;/b&gt; block scopes variable...</title><content type='html'>It looks like the &lt;B&gt;let&lt;/B&gt; block scopes variables to the block level in &lt;A HREF="https://www2.blogger.com/comment.g?blogID=7066219&amp;postID=1426619220592737413" REL="nofollow"&gt;JavaScript 1.7&lt;/A&gt; with Firefox 2.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/5387439926276085973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/5387439926276085973'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177952340000#c5387439926276085973' title=''/><author><name>Dave Murdock</name><uri>http://www.blogger.com/profile/05890407802752665754</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-948227563'/></entry><entry><id>tag:blogger.com,1999:blog-7066219.post-74269887472054192</id><published>2007-04-30T11:43:00.000-04:00</published><updated>2007-04-30T11:43:00.000-04:00</updated><title type='text'>@brook, joe, + andrew: From Crockford: "JavaScript...</title><content type='html'>@brook, joe, + andrew: From Crockford: "JavaScript's C-like syntax, including curly braces and the clunky for statement, makes it appear to be an ordinary procedural language. This is misleading because JavaScript has more in common with functional languages like Lisp or Scheme than with C or Java."&lt;BR/&gt;&lt;BR/&gt;This sums up my confusion on scoping in a nutshell. It &lt;B&gt;never&lt;/B&gt; occurred to me that if you did &lt;B&gt;for(var i...&lt;/B&gt; that &lt;B&gt;i&lt;/B&gt; was scoped at the function anyway. It also feels like I living in crazy town that if you don't use var, that i was globally scoped, I expected it was either scoped at the loop, or if you had quizzed me I would have said the function before reading all these comments, never would I have answered global. So yeah brook, I don't like the design of JavaScript here. It looks and feels like a C-derived language, but when things like this don't work like I expect from C-derived language experience, well its time to get back to basics. I am going to pick up JavaScript: The Definitive Guide based on Crockford's recommendation:&lt;BR/&gt;http://www.amazon.com/exec/obidos/ASIN/0596101996/wrrrldwideweb</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/74269887472054192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/74269887472054192'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177947780000#c74269887472054192' title=''/><author><name>Dave Murdock</name><uri>http://www.blogger.com/profile/05890407802752665754</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-948227563'/></entry><entry><id>tag:blogger.com,1999:blog-7066219.post-7611097604192292676</id><published>2007-04-30T11:32:00.000-04:00</published><updated>2007-04-30T11:32:00.000-04:00</updated><title type='text'>@Joshua Paine: The developer that orignally wrote ...</title><content type='html'>@Joshua Paine: The developer that orignally wrote the JavaScript was unintentionally declared &lt;B&gt;i&lt;/B&gt; in the global namespace. I don't know you would ever want to do this on purpose either, but maybe someone has. And I am sorry, I dislike your &lt;B&gt;if&lt;/B&gt; example, sacrificing clarity for brevity (and reducing 1 line at that) just doesn't seem worth it to me. You might understand what you wrote when you wrote it, but if you have to go back to this code and you have been using a language that has &lt;B&gt;=&lt;/B&gt; as an equality operator, not just an assignment, the fog of confusion can set in.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/7611097604192292676'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/7611097604192292676'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177947120000#c7611097604192292676' title=''/><author><name>Dave Murdock</name><uri>http://www.blogger.com/profile/05890407802752665754</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-948227563'/></entry><entry><id>tag:blogger.com,1999:blog-7066219.post-3617207024816985518</id><published>2007-04-30T11:18:00.000-04:00</published><updated>2007-04-30T11:18:00.000-04:00</updated><title type='text'>@anonymous: I haven't been schooled like that in a...</title><content type='html'>@anonymous: I haven't been schooled like that in a long time ;-). Here is some sample code (greatly simplified from the original) that will cause Firefox to use 100% CPU for a while:&lt;BR/&gt;&lt;BR/&gt;   function multipleLoops() {&lt;BR/&gt;      var startIndex = 0;&lt;BR/&gt;      var endIndex = 1000;&lt;BR/&gt;      var count = 0;&lt;BR/&gt;&lt;BR/&gt;      for(i=startIndex; i &lt; endIndex; i++) {&lt;BR/&gt;         count = count + doSomeStuff();&lt;BR/&gt;      }&lt;BR/&gt;&lt;BR/&gt;      alert(i);&lt;BR/&gt;   }&lt;BR/&gt;&lt;BR/&gt;   function doSomeStuff() {&lt;BR/&gt;      var count = 0;&lt;BR/&gt;&lt;BR/&gt;      for(i=0; i &lt; 10; i++) {&lt;BR/&gt;         count = count + i;&lt;BR/&gt;      }&lt;BR/&gt;&lt;BR/&gt;      return count;&lt;BR/&gt;   }&lt;BR/&gt;&lt;BR/&gt;This is pretty low complexity code, no branches obviously, and now both Firefox 2.0.0.3 and IE 7.0.5730.11 prompt to kill the "unresponsive script", though IE does it nearly immediately, Firefox lets it spin for 5-10 seconds. So Anon you were totally right that something else was "manipulating i", but you are wrong that we have separate code running for IE and Firefox, its all the same.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/3617207024816985518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/3617207024816985518'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177946280000#c3617207024816985518' title=''/><author><name>Dave Murdock</name><uri>http://www.blogger.com/profile/05890407802752665754</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-948227563'/></entry><entry><id>tag:blogger.com,1999:blog-7066219.post-7856538131209704465</id><published>2007-04-29T17:40:00.000-04:00</published><updated>2007-04-29T17:40:00.000-04:00</updated><title type='text'>Also, javascript limits scope only within function...</title><content type='html'>Also, javascript limits scope only within functions. Putting var within a for loop does not limit the scope of i to the loop. You can only limit the scope of i to within it's enclosing function. So to avoid confusion (as in the above) it's often recommended to var all your variables at the start of functions, rather than when they are first assigned.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/7856538131209704465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/7856538131209704465'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177882800000#c7856538131209704465' title=''/><author><name>Andrew</name><uri>http://tetlaw.id.au</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1503583491'/></entry><entry><id>tag:blogger.com,1999:blog-7066219.post-2124912961005595058</id><published>2007-04-29T11:14:00.000-04:00</published><updated>2007-04-29T11:14:00.000-04:00</updated><title type='text'>Simplifying what Brook said: this is how variable ...</title><content type='html'>Simplifying what Brook said: this is how variable scope is supposed to work in JavaScript.&lt;BR/&gt;&lt;BR/&gt;As a result, if the body of the "for" loop decrements the value of the counter, you can get an infinite loop.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/2124912961005595058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/2124912961005595058'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177859640000#c2124912961005595058' title=''/><author><name>Joe</name><uri>http://www.blogger.com/profile/16355362807496413582</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2034273356'/></entry><entry><id>tag:blogger.com,1999:blog-7066219.post-7418602775432771327</id><published>2007-04-29T09:27:00.000-04:00</published><updated>2007-04-29T09:27:00.000-04:00</updated><title type='text'>Your complaint isn't with the browsers.  Your comp...</title><content type='html'>Your complaint isn't with the browsers.  Your complaint is with ECMA-262 12.6.3, which explicitly permits for() without var in the first expression list.  Were IE and FF to get sticky over that point, they'd not be compliant with the specification.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/7418602775432771327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/7418602775432771327'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177853220000#c7418602775432771327' title=''/><author><name>Brook</name><uri>http://www.blogger.com/profile/03262265081139242297</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-502733503'/></entry><entry><id>tag:blogger.com,1999:blog-7066219.post-5058071408452781234</id><published>2007-04-29T08:00:00.000-04:00</published><updated>2007-04-29T08:00:00.000-04:00</updated><title type='text'>Anonymous is correct (about everything), and I'm g...</title><content type='html'>Anonymous is correct (about everything), and I'm glad no browsers flag failing to use var there as an error, because it's not. Two reasons:&lt;BR/&gt;&lt;BR/&gt;1) This isn't really correct:&lt;BR/&gt;&lt;BR/&gt;function bob()&lt;BR/&gt;{&lt;BR/&gt;var str='';&lt;BR/&gt;for(var i=0; i&lt;5; i++)&lt;BR/&gt;str+='yo';&lt;BR/&gt;for(var i=0; i&lt;5; i++)&lt;BR/&gt;str+='hi';&lt;BR/&gt;alert(str);&lt;BR/&gt;}&lt;BR/&gt;&lt;BR/&gt;Because i has already been declared with var, there's no need to do it again in the second loop, though Firefox at least doesn't raise an error there either.&lt;BR/&gt;&lt;BR/&gt;2) Not declaring your counter with var at all and thus polluting the global namespace and leaving yourself open to the weird interactions you experienced is something I have yet to hear of anyone doing knowingly on purpose, and it should never be done. But never is a very long time, and there might be a reason to do it that I can't think of (especially if, e.g., you did it in an inner function and the counter was declared in the containing function), so I'd hesitate to disallow it.&lt;BR/&gt;&lt;BR/&gt;In a less extreme example, Crockford and (I'm sure) many others think this is a never-do:&lt;BR/&gt;&lt;BR/&gt;if(resultINeedLater = someFunction())&lt;BR/&gt;&lt;BR/&gt;but I like the line of code it saves me, and I rarely make mistakes about assignment instead of equality, and if I do I do not find them subtle bugs but catch them easily. Just some preference of my brain that I'm glad I can indulge even though it seems like a bad idea to some.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/5058071408452781234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/5058071408452781234'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177848000000#c5058071408452781234' title=''/><author><name>Joshua Paine</name><uri>http://letterblock.com/</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1277875658'/></entry><entry><id>tag:blogger.com,1999:blog-7066219.post-787819072549434592</id><published>2007-04-29T02:22:00.000-04:00</published><updated>2007-04-29T02:22:00.000-04:00</updated><title type='text'>My apologies, code snippet should be (hopefully th...</title><content type='html'>My apologies, code snippet should be (hopefully this comes out right):&lt;BR/&gt;&lt;BR/&gt;/* prints 0 to 999 in both IE and Firefox */&lt;BR/&gt;var endIndex=1000;&lt;BR/&gt;var startIndex=0;&lt;BR/&gt;&lt;BR/&gt;for(i=startIndex; i &amp;lt; endIndex; i++) {&lt;BR/&gt;document.write(i + '&amp;lt;br&gt;');&lt;BR/&gt;//Do some stuff here&lt;BR/&gt;}</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/787819072549434592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/787819072549434592'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177827720000#c787819072549434592' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-818891271'/></entry><entry><id>tag:blogger.com,1999:blog-7066219.post-3951456944400855729</id><published>2007-04-29T02:18:00.000-04:00</published><updated>2007-04-29T02:18:00.000-04:00</updated><title type='text'>Your evaluation of what is going on in the Javascr...</title><content type='html'>Your evaluation of what is going on in the Javascript is incorrect. "i" is not initialized to startIndex at the beginning of each iteration of the loop in Firefox:&lt;BR/&gt;&lt;BR/&gt;/* prints 0 to 999 in both IE and Firefox */&lt;BR/&gt;var endIndex=1000;&lt;BR/&gt;var startIndex=0;&lt;BR/&gt;&lt;BR/&gt;for(i=startIndex; i &lt; endIndex; i++) {&lt;BR/&gt; document.write(i + '&amp;gt;br&gt;');&lt;BR/&gt;        //Do some stuff here&lt;BR/&gt;}&lt;BR/&gt;&lt;BR/&gt;My guess is that your "//Do some stuff here" manipulated (or called functions which manipulated) a variable "i" as well, and in Javascript, if you use a variable without declaring it with "var", the scope is global (otherwise it is local to the containing function). Why this does not affect Internet Explorer is anyone's guess. Without seeing the remainder of the source code, I'd speculate that there is separate code to support IE and Firefox and only the Firefox code uses another global instance of "i".&lt;BR/&gt;&lt;BR/&gt;However, as the sample code above demonstrates (tested in Firefox 2.0.0.3 and IE 7), the loop completes normally. There is no bug, error or differences between the way IE and Firefox handle the scoping rules and loop.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/3951456944400855729'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7066219/1426619220592737413/comments/default/3951456944400855729'/><link rel='alternate' type='text/html' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html?showComment=1177827480000#c3951456944400855729' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html' ref='tag:blogger.com,1999:blog-7066219.post-1426619220592737413' source='http://www.blogger.com/feeds/7066219/posts/default/1426619220592737413' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1066648336'/></entry></feed>
