Reputation: 81902
I just run into the weirdest thing I've ever encounter.
Consider this test page:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script language=javascript>
function test(myParameter) {
alert(myParameter);
}
</script>
</head>
<body>
<input type="button" value="Strange" onclick="javascript: test(044024);" />
<input type="button" value="Ok" onclick="javascript: test('044024');" />
</body>
</html>
If I click the "strange" button, I get 18452, if I click the "ok" button I get 044024
Does anyone know what is happening and explain it to me?
Upvotes: 2
Views: 201
Reputation: 17014
When you write a number with 0 as its first digit, it's an octal number.
Upvotes: 3
Reputation: 61118
Numbers prefixed with 0 are considered to be in octal (base 8)
Upvotes: 6
Reputation: 4790
Javascript is interpreting the symbol 044024 as an octal value because of the leading 0.
044024 oct to dec is 18452
Upvotes: 15