0

when I try to get arguments starting with 0, like this case here 012 it is transferring it to 010 why is that can someone explain?

function func1(a, b, c) {
  console.log(arguments[0]);

  console.log(arguments[1]);
  
  console.log(arguments[2]);
}

func1(1, 012, 3);

MDN screenshot

pilchard
  • 12,414
  • 5
  • 11
  • 23

2 Answers2

0

In JS the leading 0 converts the given number in octal base so 012 = (12)8 = (10)10

DDomen
  • 1,808
  • 1
  • 7
  • 17
0

In Javascript a number starting with 0 is interpreted as octal.

BUT the console log is showing it to you in decimal.

012 = 1*8 + 2 in decimal which is 10.

A Haworth
  • 30,908
  • 4
  • 11
  • 14