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
  • 1,558
  • 4
  • 24
  • 43

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,468
  • 3
  • 12
  • 34