Javascript learning notes-digital format type

Source: Internet
Author: User

Some people may say what format is this?
In fact, there are more than that.
1 // 1
1.2 // 1.2
1.2e3 // 1200
1.2e + 3 // 1200
1.2e-3 // 0.0012
. 12e + 2 // 12
-. 12e-2 //-0.0012

Of course, these are only decimal. Let's talk about octal and hexadecimal.
0x00, 0x11, 0xff format is hexadecimal, their decimal values are 0, 17,255.

01, 07,010,012. This is octal. (Here 0 is the number 0, not the letter o)
Some friends may have questioned whether this is decimal. How do we say it is octal?
In fact, this is octal, but it is added with a value of 0 before decimal.

Of course, not all values that add 0 are octal.
For example, 08, 09 is actually in decimal format, because 8 to 8 is carried, so it is impossible to see 08, 09.

Do you think that the field of view is much wider? It is no longer limited to decimal forms, and you don't have to be afraid of being scared by the code written by Daniel.

Some friends may say that the octal format and hexadecimal format support the e +-format?

0x12e3 === 4835
0x12e + 3 === 305
0x12e-3 == 299
0x12 = 18
Obviously, it is not the result we think about.
In fact, 0x12e3 is because e is also a hexadecimal character. The hexadecimal character is 0-9 plus a-f, Which is case insensitive, therefore, 0x12e3 is a normal hexadecimal number format.
0x12e + 3 Why not? In fact, it only adds two numbers, 0x12e decimal is 302, and 3 gets 305, so it is an expression, it is not a simple number.

The format 011e2 is incorrect, and even a syntax error is reported directly.
Therefore, the index format can only be used in decimal format.

In the future, we will not treat 1e6 as ie6.
Also, don't be depressed. 5. Why isn't it wrong? Why is. 1e1 equal to 1.

Now, let's share this small knowledge point today. Let's take a look at it.

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.