Literal literals
See what is what. For example, if we want to represent a number in the program, we write a number. To represent "Hello" in your program, you need to enclose the quotation marks. These writing rules are called literal quantities. The following is a brief explanation of the literal number and the literal character of the string.
console.log(123); console.log(你好); //这一行因为是字符串,没有引号,会产生错误 |
The literal amount of a number
Number literal: That is, the number itself. No additional symbols are required. integers can be represented as decimal (base 10), hexadecimal (radix 16), and octal (base 8). There can be three types of literals in JS. Decimal (0 to 9) integers consist of numbers without leading 0, with leading 0, 0O, and 0o in octal (0 to 7), with leading 0x, 0X all hexadecimal (0 to f). they are displayed with a 10 binary display.
Octal
console.log(15); //输出正 15 console.log(-15); //输出负 -15 console.log(07); //输出 7 console.log(010); //输出 8 console.log(036); //输出 30 , 3*8+6=30 console.log(040); //输出 32 ,3*4+0=32 console.log(0100); //输出 64 ,0*1+0*8+1*64=64 console.log(0111); //输出 73 ,1*1+1*8+1*64=73 |
Can only have 0~7 these few numbers, cannot have 8, 9. if written incorrectly, it will be 10 binary. Although it starts with 0, the number in the back is wrong and is displayed as a 10 binary.
But if the 0o (0 wow) or 0O (0 wow) starts, the following number is wrong and will error. correct
console.log(0o77); //输出88 console.log(0O77); //输出88 |
Error
console.log(0o88); // 错误 console.log(0O88); // 错误 |
Hexadecimal
16 binary, turn 10-in: 0x2af5=5x16^0+fx16^1+ax16^2+2x16^3=10997
console.log(0xff); //255 , 15*16^0+15*16^1=255 console.log(0x2b); //13 , 11*16^0+2*16^1=43 console.log(0x11); //17 |
If there is a wrong writing, that is an error.
The following numbers are all positive 15
console.log(15); console.log(017); console.log(0o17); //字母小写o console.log(0O17); //字母大写O console.log(0xf); |
The numbers below are all negative 15.
console.log(-15); console.log(-017); console.log(-0o17); //字母小写o console.log(-0O17); //字母大写O console.log(-0xf); |
Decimal
The allows you to use E to represent 10 of several parties, and decimals can omit the preceding 0. In a computer, a decimal number is called a floating point number .
console.log (3.14); //3.14 console.log ( -3.14); //-3.14 console.log (0.14); //0.14 console.log (.); //0.14 integer is 0 o'clock can omit console.log (560000); //560000 console.log (5.6e5); //560000, support index notation. 5.6*10^5 console.log (0.0001); //0.0001 console.log (1e-4); //0.0001 console.log (. 1e-3); //0.0001 can omit 0 in front of the decimal point. |
Using decimals in 8 or 16 binary will cause an error:
console.log(03.3); console.log(0x3.3); |
Special Digital Literals
Infinity infinitely large. The following attempts to output a very large number:
console.log(3e20); //300000000000000000000 console.log(3e16); //30000000000000000 console.log(3e2016); //Infinity console.log(-3e2016); //-Infinity 负无穷大 //可以直接输出 Infinity console.log(Infinity); console.log(-Infinity); |
How many numbers can generate Infinity, depending on the browser. NaN is not a number. in particular, NaN is a numeric literal.
console.log(0/0); //NaN console.log(6/0); //Infinity console.log(NaN); //NaN |
interesting phenomenon. all operations that infinity+infinity equals Infinity nan are Nan
console.log(Infinity+Infinity) //Infinity console.log(Infinity-Infinity) //NaN console.log(Infinity+-Infinity) //NaN console.log(NaN+NaN) //NaN console.log(NaN-NaN) //NaN
|
03_ the literal of a number