zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[Typescript] Improve Readability with TypeScript Numeric Separators when working with Large Numbers

typescript with when Numbers large Working NUMERIC Improve
2023-09-14 09:00:49 时间

When looking at large numbers in code (such as 1800000) it’s oftentimes difficult for the human eye to quickly see how big the number actually is. TypeScript allows us to use numeric separators to write numbers in a more human readable format (such as 1_800_000), while keeping the generated JavaScript unchanged.

 

Since Typescript 1.7, we are able to do:

const num: number = 123_456_789; // the same as 123456789

 

There is no limit how you add _ to the number, just make it reasonable.