0

Have some doubts about the javascript. when I try to console

a = 021
console.log(a) // 17

why it is changing and how to store the exact value in the variable

Gmv
  • 2,008
  • 6
  • 29
  • 46

1 Answers1

3

Because with leading zero it's a octal-number so 21 is 2*8+1 = 16.
But when you print it out it's in decimal.

Sascha
  • 4,576
  • 3
  • 13
  • 34