Use numeric separators for large numeric literals
Friday, February 21, 2020
Use numeric separators for large numeric literals
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
use numeric separators to provide visual separation in order to improve code readability
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% ?!?
Have a question or comment?