FrontendDeveloper.in

ECMAScript question detail

Numeric Separators

Numeric separators are helpful to read large numbers(or numeric literals) in JavaScript by providing separation between digits using underscores(_). In other words, numeric literals are more readable by creating a visual separation between groups of digits.

For example, one billion and one trillion becomes more readable with _ numeric separator,

const billion = 1000_000_000;
console.log(billion); // 1000000000

const trillion = 1000_000_000_000n; // BigInt number
console.log(trillion); // 1000000000000

It can be used for binary and hex literals as well.

const binaryLiteral = 0b1010_1010;
console.log(binaryLiteral);
const hexLiteral = 0xFF_FF_FF_FF;
console.log(hexLiteral);

Note: The separator can be placed anywhere within the number for readability purpose.

Back to all ECMAScript questions
Get LinkedIn Premium at Rs 399