Mr Speaker

JavaScript’s Numeric Separators

During a particularly-late night coding session, I accidentally discovered that JavaScript now has "numeric separators". What started as a simple test in my browser console: `dx=100+xo`, would be drailed by a typographical error that revealed a hidden secret…


As I depressed the underscore-instead-of-plus key, Firefox's auto-evaluator-thingy sprang into action and warned: "Uncaught SyntaxError: underscore can appear only between digits, not after the last digit in a number".

Despite my tiredness, and my usual tendency to not read error messages, it caught my eye… "an underscore can do what?" I murmered. Tentatively I added another digit to the assignment: `dx=100_0`. Hitting enter, console informed me that `dx` now had the value of 1000!

I tried some other values: 1_000_000, 1_1_1_1_1, 0xff_ff_ff… all worked - the underscores disappear and you're left with a regular ol' number! After a quick duck-duck-go I discovered that this fancy feature was called Numeric Separators and is currently in stage 3. Also, obviously, it's already implemented in Firefox (I'm on 78) - but I think Chrome too.

I'm going to dig in and see what else is coming through the TC39 pipeline… there's probably 1_000_000 other things I've missed.

Captcha! Please type 'radical' here: *
How did you find this thingo? *