JS Basic 1: Understanding the Number data type and implicit type conversions

Source: Internet
Author: User

1, Javascript only has one type of numberic data, named "Number". You can see this reflected in the behavior of the typeof operator, which classifies Intergers and Floati Ng-point numbers alike simply as numbers:

typeof ;   "Number"typeof 10.3;  "Number"typeof -1.5;  "Number"

2, in fact, all numbers be double-precision floating-point numbers, known as "doubles", which is 64-bit encolding of num Bers, keep in mind, the doubles can represent intergers perfectly with up to $ bits of precison. All of the integers from-253 to 253 is valid doubles.

3, Note that floating-point numbers is inaccurate when on arithmetic, for example, 0.1+0.2 = 0.30000000000004;

It is better to tranform the floating-point number to intergers for calculation. Ten + 30;

--------------------------------------------------------------------------------------------------------------- --------------------

4, coercisons can also hide errors (implicit type conversion may hide errors).

An undefined variable would convert to the NaN in an arithmetic calculation, which causes the calculation OT cont Inue with often confusing and unprdictable results.

JS Basic 1: Understanding the Number data type and implicit type conversions

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.