Why do leading zeros sometimes cause scripts to break and other times don't?

As the title says.

These codes work:


$gameSelfSwitches.setValue([11, 52, 'A'], true);
$gameSelfSwitches.setValue([004, 113, 'A'], true);

While these codes don't work:

$gameSelfSwitches.setValue([11, 052, 'A'], true);
$gameSelfSwitches.setValue([011, 52, 'A'], true);
$gameSelfSwitches.setValue([011, 052, 'A'], true);

Me and a friend just scrambled our brains for 2 hours before resolving this issue. . . .
The short of it: even though the RPG Maker database lists them that way, you should never include leading zeros.

JavaScript interprets any number with leading zeros as an octal value:

It sometimes works because if the number is low enough the value will be the same. For example, 004 is the value 4 in both octal and decimal.

But 011 is the value 11 in decimal and the value 9 in octal.
@ATT_Turan Thank you for your response. It begins to make sense now.

Original thread: https://forums.rpgmakerweb.com/threads/why-do-leading-zeros-sometimes-cause-scripts-to-break-and-other-times-dont.155822/