3 ms·
> Either the leading zero is ignored, or it indicates octal, as it does in many languages, including JavaScript. This is false. In JavaScript, a leading zero,
by johnhenry 7y ago
> Either the leading zero is ignored, or it indicates octal, as it does in many languages, including JavaScript.
This is false. In JavaScript, a leading zero, unless accompanied by a lowercase oh ('o') does indicate the number is written in octal.
08 === 0o10; // true
Here, the left side is still base 10, while the right side is base 8.
- reificator 7y agoI wouldn't say it's false, I would say it's no longer true in strict mode. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Javascript for many years has assumed a leading zero means an octal prefix, and it's only recently that behavior has changed. EDIT: Also your example does not disprove this. Here's another example that you should try running in the console: 011 === 11; // false 011; // 9
- johnhenry 7y agoThanks for the link! EDIT: Also, yes, I the mistake with my initial example -- as '8' doesn't exist in octal, we have no choice but to interpret the leading '0' as padding and '08' as base ten, whereas '11' can be interpreted as base eight.
- samatman 7y agoIt's not false, because it's perfectly reasonable to describe both ES5 and ES6 as "JavaScript". It is, at best, no longer true.