zl程序教程

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

当前栏目

[Javascript] Javascript numeric separators

JavaScript NUMERIC
2023-09-14 08:59:14 时间

Big or non decimal numbers are sometimes hard to read inside code. Numeric separators are now part of the javascript specification and allow us to make numbers in our code more readable for humans. In this lesson we will learn how to use numeric separators and the limitations of usage.

 

const bigNumber = 1999999999999;
console.log(bigNumber);

const bigReadableumber = 1_999_999_999_999;
console.log(bigReadableumber);

console.log(275.789897);
console.log(275.789_897);

console.log(0b0100_1010_1110_1010);

const myBigInt = 1_234_567_890_123_456_789_012n;
console.log(myBigInt.toString());

// const badReadable = 1111__1111; bad
// const badReadable2 = 11111_; bad
// const binary = 0b_1111; bad