+ 4
When We declare a variable why do we get different value if we add 0's in the beginning?
say a var x=001400 document.write(x) The output is 768 ....why
2 Réponses
+ 3
It happens because..it is converted from hexadecimal format to the normal format.
because javascript think it is a hexadecimal number that u declared..since it has preceding zeros.
0
when ever u add 0x.... before to number it consider as hexadecimal number
if u add 0.... it consider as octal(base 8) number
If you do alert or doc..write, by default they
convert them to string
default convention of number toString is with base 10,
to get exact value as what u give, write x.toString(8)
but in string conversion obviously it removes preceding zeros of number