Chapter 3, (40p) parseInt("070") returns 56 not 0 in ECMAScript5
In chapter 3 (40p), discussion of parseInt() function, the book reads like following:
//56 (octal) in ECMAScript 3, 0 (decimal) in ECMAScript 5
var num = parseInt("070");
I tried this in my firefox browser, like following:
<script type="text/javascript">
"use strict";
var a = parseInt("070");
console.log(a); // 56
</script>
I can' sure this is error or common quirks, or maybe I don' know something important. If I'm wrong, how can I force the browser to use ECMA 5?
-----------------------
and the succeeding description, the book reads like this:
In ECMAScript 5 JavaScript engines, the ability to parse octal values has been removed from parseInt() so the leading zero is considered invalid and the value is treated the same as â0â, resulting in the decimal value 0.
What I don' understand is that, if the engine removed octal conversion, then shouldn' it convert the literal as if it were decimal, so that parseInt("070") should return "70"?. I think that makes sense.
so.. I hope some clearer discussion so I understand why parseInt('070') in ECMA 5 should return "0".
|