Reputation: 13166
I have the codes below:
<script type="javascript">
var item = 001002004;
alert(item);
</script>
Whenever I see this page in view source in my web browser, I see these lines of code exactly as same as here. But when alert()
function runs, I see an unknown message. It alrest '6295553'. I don't know where is this unknown value from. I'm sure anything don't happen to item
and it did not change before of alert
.
What do you think ? What's the problem ?
Upvotes: 2
Views: 110
Reputation: 79830
Any number prefixed with 0 will be considered as octal. and 0x for hexa decimal
I am guessing that you are having it as an numeric value like below or using parseInt function to parse the string and when you alert it you see a different value..
var item = 001002004;
alert(item);
Or probably you are doing something like below
var item = '001002004';
alert(parseInt(item));
See more details on parseInt @MDN
Upvotes: 5
Reputation: 70538
are you sure you are not changing the variable -- maybe with a cap. eg
var item = 'some value';
alert(Item);
Upvotes: 0
Reputation: 122936
Try changing the script type to "text/javascript" <script type="text/javascript">
, or don't use the type
attribute at all. See this jsfiddle
Upvotes: 1
Reputation: 9026
Please have a look at above fiddle. It does not alert anything anomalous for me.
Upvotes: 0