3 ms·
Another fun one to figure out is: 072 === 058 // returns true Thankfully, doesn't work in strict mode.
by waf 6y ago
Another fun one to figure out is:
072 === 058 // returns true
Thankfully, doesn't work in strict mode.
- josefx 6y agoIf that is a combination of octal and decimal how is 058 not a parser error?
- tempodox 6y ago`072` is interpreted as octal, and `058` is interpreted as decimal (7·8+2 = 58). Ah, the dumpster fire that is JavaScript.
- masswerk 6y agoPrefixing octal numbers by zero was a common convention. The real dumpster fire was all those intermediate years without an octal notation in strict mode. (If you needed them, either forget strict mode, or choose between converting to meaningless decimals or using strings and feeding them through parseInt. What's sane about this?) However, 058 should have been a parse error.
- tempodox 6y agoI agree. That inconsistency in how the `0` prefix is handled shouldn't exist.