This format stores numbers in 64 bits,
- 0-51 bit stores value(fraction)
- 52-62 bit stores exponent
- 63-bit stores sign
The types of number literals You can use decimal, binary, octal, and hexadecimal.
- Decimal Numbers:
Var a=33; var b=3.3; var x = 0562 //x will be 370(parsed as an octal number).
- If the number starts with 0 and the following number is smaller than 8. It will be parsed as an Octal Number.
Integers are accurate up to 15 digits:
var a = 999999999999999; // a will be 999999999999999 var b = 9999999999999999; // b will be 10000000000000000
- The floating point is not 100% accurate. The maximum number of decimals is up to 17.
var x = 0.22 + 0.12; //x will be 0.33999999999999997
- Binary Numbers
They start with 0b or 0B followed by 0’s and 1’s.
var x = 0b11; // x will be 3 var x = 0B0111; // x will be 7
- Octal Numbers
They start with 0 followed by a number of ranges from 0-7. If any number is used it will be taken as a decimal number.
var x = 0111; //x will be 73 var x = 07123; //x will be 3667
- Hexadecimal Numbers
They start with 0x or 0X followed by any digit belonging (0123456789ABCDEF)
var x = 0xfff; //x will be 4095
var x = 2E5 // x will be 200000 var x = 34e3 // x will be 34000 var x = 23e-5 //x will be 0.00023
var a = 20; var b = 20; var c = a + b; // c will be 40 (a number)
var a = "10"; var b = "20"; var c = a + b; // c will be 1020 (a string)
- Numeric Strings
NaN is a reserved word indicating not a number.
var x= "12345" ; // x will be a string(NaN) var x = 67 ; // x will be number