In our case, if we want to store some numeric value we need to use a number data type.
If we use values larger than this we may lose precision in trailing digits.
Let’s look into it one by one.
5 88 56 555986547
It uses 0 to 9 or a(or A) to f(or F) witch represents values from 10 to 15.
0xfca99 // => 1034905 = (15 × 16⁴) + (12 × 16³) + (10 × 16²) + (9 × 16¹) + (9 × 16⁰) 8873 // => 34931 = (8 × 16³) + (8 × 16²) + (7 × 16¹) + (3 × 16⁰)
In ES6 and later, we can also represent integers in binary(base-2) or octal(base-8) using prefixes 0b and 0o(or 0B and 0O) respectively.
0b110110110 // => (1 × 2⁸) + (1 × 2⁷) + (0 × 2⁶) + (1 × 2⁵) + (1 × 2⁴) + (0 × 2³) + (1 × 2²) + (1 × 2¹) + (0 × 2⁰) 0o57246 // => (5 × 8⁴) + (7 × 8³) + (2 × 8²) + (4 × 8¹) + (6 × 8⁰)
Floating-point literals can have decimal point.
A real value is represented as an integral part of the number, followed by a decimal point and fractional part of the number.
Floating-point literals can also be represented using exponential notation.
A real number followed by letter e(or E) with optional +/- sign, followed by an integer exponent.
This notation represents a real number multiplied by 10 to the power of the exponent.
3.14 55482.2287 7.9985e33 // => 7.9985 × 10²³ 1.221533E-11 // => 1.221533 × 10⁻¹¹
We can use separators in numeric literals to make them easier to read.
let no1 = 1_000_222_444; let no2 = 2.111_125_255
At the moment, using an underscore in numeric literals is not formally standardized yet. But they are in the advanced stage of the standardization process and implemented by major browsers and Node.
These includes +, -, *, /, and %.
%(Modulo) is used to get a remainder after division.
ES2016 adds ** for exponentiation.
20**4 // => 160000
When the number(or a result of the operation) is larger than the largest representable number(overflow), the resulting value is a special infinite value, Infinity.
Similarly, if the number(or a result of the operation) is smaller than the smallest representable value, the resulting special value is negative infinity, -Infinity.
The zero divide by zero does not have a well-defined value and the result of this operation is a special not-a-number value(NaN).
Hope you like it, if yes **like & share.**
Thanks for your time.