This format stores numbers in 64 bits,
- 0-51 bit stores value(fraction)
- 52-62 bit stores exponent
- 63-bit stores sign
Number Literals: The types of number literals You can use decimal, binary, octal, and hexadecimal.
let a=33; let b=3.3;
Octal Number: If the number starts with 0 and the following number is smaller than 8. It will be parsed as an Octal Number.
let x = 0562 // x will be 370(parsed as an octal number).
Binary Numbers: They start with 0b or 0B followed by 0’s and 1’s.
let x = 0b11; // x will be 3 let x = 0B0111; // x will be 7
Hexadecimal Numbers: They start with 0x or 0X followed by any digit belonging (0123456789ABCDEF)
let x = 0xfff; // x will be 4095
Example 1: In this example, we will print different numbers literals.
323 3 7 4095 370
Integers are accurate up to 15 digits
let a = 999999999999999; // a will be 999999999999999 let b = 9999999999999999; // b will be 10000000000000000
The floating point is not 100% accurate. The maximum number of decimals is up to 17.
let x = 0.22 + 0.12; //x will be 0.33999999999999997
Example 2: In this example, we will check the output for the above inputs.
Example 3: In this example, we will use Number methods such as toString(), toExponential(), toPrecision(), isInteger(), and toLocaleString() method.
21 2.1e+1 21.00 true ২১
- If you add a string and number, there will be a string concatenation as an output.
Please Login to comment...