问题
I have a function where I passes the value dynamically
<a href="javascript:void(0);" onclick="searchError(0011)">0011</a>
In javascript am just passing this value and it returns me 9
JS
function searchError(s){
alert(s);
}
Need help to understand why ?
I fixed it by quoting the value like
<a href="javascript:void(0);" onclick="searchError('0011')">0011</a>
JS Fiddle
回答1:
0011
is an octal number since it has a leftmost 0
so its equal to 0 x 82 + 1 x 81 + 1 x 80 = 9. Originally the value was interpreted as a numeric. Enclosing it in quotes caused it to be treated as a String literal.
来源:https://stackoverflow.com/questions/27871143/javascript-returns-9-for-0011