JavaScript type and type judgment

Source: Internet
Author: User

JS in the type:

Standard type: number, String, Boolean, Null, Undefined

Built-in object types: Function, Array, Date, RegExp, Math, JSON ...

Type identification:

1, typeof: Can identify the standard type (except Null, undefined), cannot judge the object, because all the specific object types are judged to be object,function except. such as typeof "123";//string

2, instanceof: Can identify the built-in object type, custom object type, does not recognize the standard type. such as: [] instanceof Array;//true

3, Object.prototype.toString.call: Can recognize the standard type, the built-in object type, does not recognize the custom object type. such as: Object.prototype.toString.call ("123"). Slice (8,-1);//string

4, constructor: All types can be recognized (except Null, undefined, because there is no constructor). such as: "123". constructor===string; True to find out who the Obj object is constructed from

JavaScript type and type judgment

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.