JavaScript Advanced Programming Reading notes-data types

Source: Internet
Author: User

There are 5 simple data types (basic data types) in ECMAScript: Undefined, Null, Boolean, number, and string, and a complex data type--object,object essentially consists of a set of unordered name-value pairs. 1. typeof operatorUsing the typeof operator on a value may return one of the following strings:
    • "Undefined"--if this value is undefined
    • "Boolean"--if this value is a Boolean value
    • "String"--if this value is a string
    • "Number"--if the value is numeric
    • "Object"--if this value is an object or null
    • "Function"--if this value is a function
2. Undefined value is derived from null value, so null==undefined is true   3. Number Typevar intnum=55; Decimal      var octalnum1=070; Eight-binary 56      var octalnum2=079; Invalid octal value, resolved to 79        var octalnum2=08;     Invalid octal value, parsed to 8 var hexnum1=0xa;     Hex of the ten Var hexnum2=0x1f; Hex of 31
    • NaN
NaN, or non-numeric (not a number) is a special value that represents a case where the operand that would have returned a numeric value did not return a numeric value (for example, dividing by 0 would return Nan).     Nan itself has two characteristics: first, any operation that designs Nan will return Nan, and second, Nan and any value do not want to wait, including Nan itself (for example, Nan==nan returns false). For these two features, ECMAScript defines the IsNaN () function (for example: IsNaN (NaN) returns True).
    • numeric conversions
There are 3 functions that can convert non-numeric values to numeric values: Number (), parseint (), and parsefloat ().     Number () can be used for any data type, while the other two functions are dedicated to string conversion values. The conversion rules for the number () function are as follows:
      • If it is a Boolean value, True and false are converted to 1 and 0, respectively.
      • If it is a null value, 0 is returned.
      • If it is undefined, return nan.
      • If it is a string:
        • If it contains only numbers, it is converted to decimal values.
        • If a valid floating-point format is included, it is converted to a floating-point value.
        • If a valid hexadecimal is included, such as "0xf", the decimal integer value is converted to the same size.
        • If the string is empty, it is converted to 0.
        • If the string contains characters other than the above, it is converted to Nan.
      • If it is an object, the object's valueof () method is called and then converted according to the previous rule. If the conversion result is Nan, the object's ToString () method is called and then converted according to the preceding rule.
parseint () function conversion rule: (whitespace before the string is ignored until the first non-whitespace character is found
      • Returns Nan if the first character is not a numeric character or a minus sign.
      • If the first character is a numeric character, the next character continues to be parsed until all characters have been parsed or a non-numeric character is encountered. (For example, "1234blue" returns 1234)
      • If the string starts with "0x" and is followed by a numeric character, it is converted to decimal as 16, and if it starts with "0", it is converted to decimal as an octal binary. (Note: parseint ("* * * *", 16), the second parameter specifies hexadecimal parsing, and so on)
Parsefloat () is similar to parseint () and is parsed from the first character, and stops if an invalid floating-point number character is encountered, ignoring the subsequent string (for example: "22.34.5" returns 22.34). The second difference is that it always ignores the leading 0. An integer is returned if it can be resolved to an integer. 4. String TypeWhen you call the ToString () method of a number, you pass a parameter: the cardinality of the output value. Null and undefined do not have the ToString () method.     If you do not know if it is null or undefined, you can use the Transform function string (): Var value1=10;     var value2=true;     var value3=null;     var value4;     Alert (String (value1));     "Ten" alert (String (value2));     "True" alert (String (VALUE3));     "Null" alert (String (VALUE4)); "Undefined" 5. Type of ObjectEach instance of object has the following properties and methods:
    • Constructor: Holds the function that is used to create the current object.
    • hasOwnProperty (PropertyName): Used to check whether a given property exists in the current object instance.
    • isPrototypeOf (object): Used to check whether an incoming object is a prototype of an incoming object.
    • propertyIsEnumerable (PropertyName): Used to check whether a given property can use the For-in statement.
    • toLocaleString (): Returns the string representation of the object that corresponds to the region where the execution environment is executed.
    • ToString (): Returns the string representation of the object.
    • ValueOf (): Returns the string, numeric, or Boolean representation of an object, usually the same as the ToString () method.

JavaScript Advanced Programming Reading notes-data types

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.