lookout.devlookout.dev
search
Share Knowledge
10

Use numeric separators for large numeric literals

Friday, February 21, 2020

Numeric separators provide improved readability of large numeric literals by creating a visual separation between the digit groups. The numeric separators proposal for ECMAScript is currently a stage 3 proposal, has been implemented in TypeScript 2.7, and is already available in Chrome, Firefox and Safari. Check out caniuse.com for the latest support of numeric separators in modern browsers.

Instructions

checkmark-circle
Do

use numeric separators to provide visual separation in order to improve code readability

error-circle
Avoid

large numeric literals without visual separators

Code Examples

use numeric separators

const BIG = 1_000_000_000   // ohh, it _is_ a billion!

const APR = 26_99 // phew, only 26.99%

large numeric literals without separators

const BIG = 1000000000   // it's a billion. no, ten million. maybe, 10 billion. ugh

const APR = 2699 // is that 26.99 percent or 2,699% ?!?
Brian Love

I am a software engineer and Google Developer Expert in Web Technologies and Angular with a passion for learning, writing, speaking, teaching and mentoring. I regularly speaks at conferences and meetups around the country, and co-authored "Why Angular for the Enterprise" for O'Reilly. When not coding, I enjoy skiing, hiking, and being in the outdoors. I started lookout.dev to break down the barriers of learning in public. Learning in public fosters growth - for ourselves and others.

Google Developers Expert

Have a question or comment?