JavaScript Numeric Separators

Writing good code is important — writing code that’s easily human readable is a next level skill. It’s not often that APIs are introduced whose seemingly only useful function is making code more readable, but let me introduce you to JavaScript numeric separators: an API that lets developers use underscores to make numbers more readable! […]

The post JavaScript Numeric Separators appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh

Writing good code is important — writing code that’s easily human readable is a next level skill. It’s not often that APIs are introduced whose seemingly only useful function is making code more readable, but let me introduce you to JavaScript numeric separators: an API that lets developers use underscores to make numbers more readable!

Consider the following number in your code:

// No commas for numbers in JavaScript
const oneHundredThousand = 100000;

Large numbers have always been difficult to mentally parse for engineers, so using underscores to make code more readable is a total win:

const oneMillion = 1_000_000; // 1000000
const decimals = 1_000_00.01_02_03 // 100000.010203

The only real rule with numeric separators is that the number cannot start or end with an underscore.

Numeric separators within JavaScript seem like spec creators gifting developers a feature. As an engineer, I’ll take all I can get. You never stop learning in the world of JavaScript!

The post JavaScript Numeric Separators appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2021-06-10T02:07:38+00:00) JavaScript Numeric Separators. Retrieved from https://www.scien.cx/2021/06/10/javascript-numeric-separators/

MLA
" » JavaScript Numeric Separators." David Walsh | Sciencx - Thursday June 10, 2021, https://www.scien.cx/2021/06/10/javascript-numeric-separators/
HARVARD
David Walsh | Sciencx Thursday June 10, 2021 » JavaScript Numeric Separators., viewed ,<https://www.scien.cx/2021/06/10/javascript-numeric-separators/>
VANCOUVER
David Walsh | Sciencx - » JavaScript Numeric Separators. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/10/javascript-numeric-separators/
CHICAGO
" » JavaScript Numeric Separators." David Walsh | Sciencx - Accessed . https://www.scien.cx/2021/06/10/javascript-numeric-separators/
IEEE
" » JavaScript Numeric Separators." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2021/06/10/javascript-numeric-separators/. [Accessed: ]
rf:citation
» JavaScript Numeric Separators | David Walsh | Sciencx | https://www.scien.cx/2021/06/10/javascript-numeric-separators/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.