Numbers in JavaScript

Source: Internet
Author: User

1 digit

Numbers are one of the basic data types in javascript. javascript does not distinguish integer and floating-point values. Javascript uses the 64-bit floating format defined in the IEEE 754 standard, basically similar to the double type in Java.

Javascript supports direct numeric values: integer values, octal and hexadecimal values, and floating point values.

 

2. Number object

Number object, which is the packaging object of the original value. When necessary, JavaScript will automatically convert between the original data and the object.

The constructor Number () can be used directly as a conversion function instead of the new operator. When you call Number () in this way, it will convert its parameter into a Number, and then return the converted original value (or NaN ). Constructors are usually used as placeholders for five useful numeric constants, these five useful numeric constants are the maximum number that can be expressed, the minimum number that can be expressed, positive infinity, negative infinity, and special NaN values. Similar to the static member attribute in c #, it cannot be instantiated.

 

Number. MAX_VALUE

The maximum number that can be expressed.

Number. MIN_VALUE

The smallest number that can be expressed.

Number. NAN

Special Non-numeric value

Number. POSITIVE_INFINITY

Special Value indicating positive infinity

Number. NEGATIVE_INFINITY

Special Value of negative infinity

There are two special value constants Infinity and NaN, representing Infinity and non-numbers, respectively.

NaN! = NaN

Infinity = Infinity

Number. POSITIVE_INFINITY: Infinity

 

Number. NEGATIVE_INFINITY:-Infinity

 

 

 

Two special functions are used to determine special values.

IsNaN ()

Check special value NaN. NaN! = NaN, but isNaN (NaN) = true;

IsFinite ()

Checks whether a number is NaN, positive, or negative.

 

 

 

 

An issue with isNaN (): it implicitly converts its parameter to a number, so even if the parameter is a string that cannot be converted to a number, it will also return true (converted to NaN), so it does not use the type detection to directly judge, the following version can solve the problem:

Number. isNaN = function (value ){
Return typeof value = 'number' & isNaN (value );
};

Three-digit calculation

Use the Arithmetic Operators (+,-, *,/, etc.) or use the functions of the Math object for calculation.

 

 

References are as follows (if there is any infringement, please contact me in time ):

Javascript authoritative guide (fifth edition)

Http://www.w3school.com.cn/js/pro_js_referencetypes.asp

Http://www.cnblogs.com/ziyunfei/archive/2012/09/19/2690866.html

Related Article

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.