title: Hack to convert javascript number to UInt32
body: <p><strong>Edit:</strong> This question is out of date as the Polyfill example has been updated. I'm leaving the question here just for reference. Read the correct answer for useful information on bitwise shift operators.</p>
  
  <hr>
  
  <p><strong>Question:</strong></p>
  
  <p>On line 7 in the Polyfill example of the Mozilla <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf" rel="noreferrer" title="Mozilla Array.indexOf">Array.prototype.indexOf</a> page they comment this:</p>
  
  <pre><code>var length = this.length &gt;&gt;&gt; 0; // Hack to convert object.length to a UInt32
  </code></pre>
  
  <p>But the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise_operators" rel="noreferrer" title="Bitwise operators - Mozilla">bitwise shift</a> specification on Mozilla clearly states that the operator returns a value of the same type as the left operand: </p>
  
  <blockquote>
    <p>Shift operators convert their operands to thirty-two-bit integers and return a result of the same type as the left operand.</p>
  </blockquote>
  
  <p>So shouldn't length receive the standard 64-bit float value? Or can someone point out to me where the hack starts?</p>