In JavaScript, all numbers are defined in double precision 64-bit binary format IEEE 754 i.e, the numbers between -(253 -1) and 253 -1). There are no Specific type for integers and to represent floating-point numbers, it has three symbolic values i.e, +infinity, -infinity and NaN(not a number).
There are four types of number literals. They are: decimal, binary, octal and hexadecimal.
Decimal Numbers
The Decimal literal can start with zero(0) and followed by another decimal digit. If any digit followed by zero(0) is smaller than number 8, than the number gets parsed as a octal number.
0888 // 888 parsed as decimal
0666 // parsed as octal
Binary Numbers
Binary number syntax starts with a zero(0) followed by a lower case or upper case Latin letter "B" (0B or 0b). If the digits after 0b are not followed by 0 or 1, then "Missing binary digits after 0B" syntax error is shown.
Octal Numbers
Octal Number syntax uses a leading zero. If the digits after 0 has range between 0 and 7 are defined as octal number otherwise it will be decimal number.
var a = 0453; //453
var b = 0333; //333
In ECMAScript 5, the octal numbers are supported if they are prefixed with 0o.
Hexadecimal Numbers
Hexadecimal numbers uses a number zero followed by a lowercase and uppercase Latin letter 0X. (0X or 0x). If the digits after 0x (123456789ABCDEF) doesn't follow these values then following syntax error is thrown i.e, Identifier starts immediately after numeric literal.
Ex: 0xFFFFFFFFFFFFFFFFF
There are four types of number literals. They are: decimal, binary, octal and hexadecimal.
Decimal Numbers
The Decimal literal can start with zero(0) and followed by another decimal digit. If any digit followed by zero(0) is smaller than number 8, than the number gets parsed as a octal number.
0888 // 888 parsed as decimal
0666 // parsed as octal
Binary Numbers
Binary number syntax starts with a zero(0) followed by a lower case or upper case Latin letter "B" (0B or 0b). If the digits after 0b are not followed by 0 or 1, then "Missing binary digits after 0B" syntax error is shown.
Octal Numbers
Octal Number syntax uses a leading zero. If the digits after 0 has range between 0 and 7 are defined as octal number otherwise it will be decimal number.
var a = 0453; //453
var b = 0333; //333
In ECMAScript 5, the octal numbers are supported if they are prefixed with 0o.
Hexadecimal Numbers
Hexadecimal numbers uses a number zero followed by a lowercase and uppercase Latin letter 0X. (0X or 0x). If the digits after 0x (123456789ABCDEF) doesn't follow these values then following syntax error is thrown i.e, Identifier starts immediately after numeric literal.
Ex: 0xFFFFFFFFFFFFFFFFF
No comments:
Post a Comment