03_ the literal of a number

Source: Internet
Author: User

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); //输出正 15console.log(-15); //输出负 -15console.log(07); //输出 7console.log(010); //输出 8console.log(036); //输出 30 , 3*8+6=30console.log(040); //输出 32 ,3*4+0=32console.log(0100); //输出 64 ,0*1+0*8+1*64=64console.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.
console.log(088); //输出88
  But if the 0o (0 wow) or 0O (0 wow) starts, the following number is wrong and will error.  correct
console.log(0o77); //输出88console.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=255console.log(0x2b); //13 , 11*16^0+2*16^1=43console.log(0x11); //17
  If there is a wrong writing, that is an error.
console.log(0x2m); //出错
  The following numbers are all positive 15
console.log(15);console.log(017);console.log(0o17); //字母小写oconsole.log(0O17); //字母大写Oconsole.log(0xf);
  The numbers below are all negative 15.
console.log(-15);console.log(-017);console.log(-0o17); //字母小写oconsole.log(-0O17); //字母大写Oconsole.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); //300000000000000000000console.log(3e16); //30000000000000000console.log(3e2016); //Infinityconsole.log(-3e2016); //-Infinity 负无穷大//可以直接输出 Infinityconsole.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); //NaNconsole.log(6/0); //Infinityconsole.log(NaN); //NaN
  interesting phenomenon.  all operations that infinity+infinity equals Infinity nan are Nan
console.log(Infinity+Infinity) //Infinityconsole.log(Infinity-Infinity) //NaNconsole.log(Infinity+-Infinity) //NaNconsole.log(NaN+NaN) //NaNconsole.log(NaN-NaN) //NaN

 

03_ the literal of a number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.