Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Mozilla <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseInt">tells us</a>:</p> <blockquote> <p>function parseInt <strong>converts its first argument to a string</strong>, parses it, and returns an integer or NaN. If not NaN, the returned value will be the decimal integer representation of the first argument taken as a number in the specified radix (base). For example, a radix of 10 indicates to convert from a decimal number, 8 octal, 16 hexadecimal, and so on. For radices above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.</p> </blockquote> <p>In <a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">the spec</a>, 15.1.2.2/1 tells us that the conversion to string is performed using the built-in <code>ToString</code>, which (as per 9.8) yields <code>"null"</code> (not to be confused with <code>toString</code>, which would yield <code>"[object Window]"</code>!).</p> <p>So, let's consider <code>parseInt("null", 24)</code>.</p> <p>Of course, this isn't a base-24 numeric string in entirety, but "n" is: it's <em>decimal 23</em>. </p> <p>Now, parsing stops after the decimal 23 is pulled out, because <code>"u"</code> <em>isn't</em> found in the base-24 system:</p> <blockquote> <p>If S contains any character that is not a radix-R digit, then let Z be the substring of S consisting of all characters before the first such character; otherwise, let Z be S. [15.1.2.2/11]</p> </blockquote> <p>(And this is why <code>parseInt(null, 23)</code> (and lower radices) gives you <code>NaN</code> rather than 23: <code>"n"</code> is not in the base-23 system.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload