title: How do I work around JavaScript's parseInt octal behavior?
body: <p>Try executing the following in JavaScript:</p>
  
  <pre><code>parseInt('01'); //equals 1
  parseInt('02'); //equals 2
  parseInt('03'); //equals 3
  parseInt('04'); //equals 4
  parseInt('05'); //equals 5
  parseInt('06'); //equals 6
  parseInt('07'); //equals 7
  parseInt('08'); //equals 0 !!
  parseInt('09'); //equals 0 !!
  </code></pre>
  
  <p>I just learned the hard way that JavaScript thinks the leading zero indicates an <a href="http://en.wikipedia.org/wiki/Octal" rel="noreferrer">octal integer</a>, and since there is no <code>"8"</code> or <code>"9"</code> in base-8, the function returns zero. Like it or not, <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt" rel="noreferrer">this is by design</a>.</p>
  
  <p>What are the workarounds?</p>
  
  <p><em>Note: For sake of completeness, I'm about to post a solution, but it's a solution that I hate, so please post other/better answers.</em></p>
  
  <hr>
  
  <p><strong>Update:</strong> </p>
  
  <p>The 5th Edition of the JavaScript standard (<a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" rel="noreferrer">ECMA-262</a>) introduces a breaking change that eliminates this behavior. Mozilla has a good <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseInt#ECMAScript_5_Removes_Octal_Interpretation" rel="noreferrer">write-up</a>. </p>