javascript-Data types

Source: Internet
Author: User

A summary of the advanced programming of JavaScript

JavaScript data type:

    • undefined:undefined ( variable declaration but Undefined for initialization)
    • Null:null (Null object pointer, variable will save object type, can be assigned to null first)
    • Boolean
    • Number
    • String
    • Object

Typeof operator

Value: Undefined, Boolean, string, number, object, function

typeof NULL // Object,null is considered a reference to an empty object

null = = undefined     //truenull//false

!!! Using only typeof to detect the type is not too perfect

Boolean

Data type Convert to True Convert to False
Boolean True False
String Any non-empty string "" (empty string)
Number Any non-0 digits (including infinity) 0 and Nan
Object Any object Null
Undefined Undefined

Correlation function: Boolean ()

Number Type

Use IEEE754 to represent integers and floating-point numbers

If there is no decimal place, the floating-point number is parsed into integers

>1.0< 1

Floating-point calculation with error

var a = 0.1var b = 0.3if (a+b = = 0.3) {  ...   .. // will not be executed }//0.1+0.2 =0.30000000000000004

    • The maximum and minimum values that JavaScript can represent:

Maximum value: Number.MAX_VALUE

Minimum value: Number.min_value

Exceeding the maximum minimum value is considered to be positive infinity and negative infinity

Positive Infinity: Infinity//Number.POSITIVE_INFINITY

Negative Infinity:-infinity//number.negative_infinity

Correlation function: Isfinite ()//returns true between Number.MAX_VALUE and Number.min_value, otherwise false

    • NaN
      • Any number divided by 0 will return Nan
      • Nan and Nan Range
      • // false
      • Correlation function: IsNaN ()
    • numeric conversions (explicit and implicit)
      • Correlation functions: Number (), parseint (), parsefloat (), and the latter two only for strings; Paseint can be passed into the input parameters 2,8,10,16

Number ()

    • Boolean, True and False are converted to 1, 0, respectively
    • Number type, simple incoming and returned
    • Null,null return 0
    • undefined,undefined return Nan
    • String, can be turned, null character converted to 0, other Nan
    • Object type, call valueof (), go to the above rule, and if the conversion result is Nan, then call ToString () and convert to a string according to the above rule

String

The string is a 16-bit Unicode sequence and is immutable. Special characters to be escaped

Correlation function: String () toString ()

ToString (): null, undefined no this method for numeric-accessible binary arguments

String () "Indeterminate object has no ToString method"

If the object has the ToString () method, call the method (no arguments) and return the result

If NULL, returns "NULL"

If undefined, returns "undefined"

Object

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

The above is the type of general understanding, you can know the new ~

javascript-Data types

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.