Javatpoint Logo
Javatpoint Logo

JavaScript numerical separator

The human eye takes a long time to parse large numerical literals, particularly if many repeated digits exist.

A new JavaScript programming feature allows underscores to be used as separators in numerical literals, which makes them easier to understand.

A JavaScript feature called numeric separators enables us to utilize underscore as a separator for the numeric literals.

For example, the number 10000 can be written as 10_000. Both Node.js and modern browsers' most recent iterations support the capability.

Syntax

The following syntax shows the numerical separator in JavaScript.

Examples

The examples show to operate numeric separators for binary, hexadecimal, and another type of values.

Example1:

The following example shows a basic numeric separator in javascript for simple values. We can use decimal and simple numeric values and separators. The separator can place any position of the number, and it does not affect the original number.

Output

The image shows actual values and numerical separator output.

JavaScript numerical separator

Example 2:

The following example shows a numeric separator in javascript for numerical values. We can use big integers and binary values with the separator. The separator can place any index number of the input number.

Output

The image shows actual values and numerical separator output.

JavaScript numerical separator

Example 3:

The following example shows a numeric separator in javascript for various numerical values. We can use octal and hexadecimal values with the separator. The separator can place any index number of the input number.

Output

The image shows actual values and numerical separator output.

JavaScript numerical separator

Example 4:

The following example shows a numeric separator in JavaScript for numerical values. We can use big integers and binary values with the separator. The separator can place any index number of the input number. Here, we can use addition, subtraction, and multiplication of the values.

Output

The image shows actual values and numerical separator output.

JavaScript numerical separator

Conclusion

JavaScript numeric separator is a visual operator to understand code and long values. It helps to understand complicated mathematical operations and displays large-size data.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA