JS data type

Source: Internet
Author: User

First, the data type

There are 5 basic data types in ECMAScript, undefined, null, Boolen, number, string, respectively. There is also a complex data type object. object is essentially composed of a set of unordered name-value pairs.

Second, typeof operator

Using an operator on a value may return one of the following strings:

    • ' Undefined '----If this value is not defined;
    • ' Boolen '----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.

typeof 2==number;

typeof Nan==number;

var message= ' SSS ';

typeof Message==string;

typeof Null==object;

Third, instanceof operator

result= variable instanceof constructor;result==true or false;

Person instanceof object//variable person is object?

numeric conversions

There are three functions that convert a non-numeric value to a value: Number (), parseint (), parsefloat (). parseint () is more commonly used when working with integers.

Convert to String

(1) Numeric, Boolean, object, and string values have a ToString () method, but the null and undefined values do not have this method.

var num=10;

Alert (num.tostring ()); "10"

Alert (num.tostring (2)); "1010"

(2) A string () can be called when the value is not known to be null or undefined;

var value1=10;

var value2=true;

var value3=null;

var value4;

Alert (String (value1)); "10"

Alert (String (value2)); "True"

Alert (String (VALUE3)); "NULL"

Alert (String (VALUE4)); "Undefuned"

Object type

An 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 is in an instance of the current object (not in the round prototype of the current instance), where the property name of the parameter propername must be specified as a string.
    • Ispropertyof (object): Used to check if an incoming object is a prototype of another object.
    • propertyIsEnumerable (PropertyName): Used to check whether a given property can be enumerated using the For-in statement.
    • toLocaleString (), toString (), ValueOf ().

JS data type

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.