JS judging the type of object

Source: Internet
Author: User


In development, it is unavoidable to judge the object type, and to enumerate the common judgment methods:

1.typeof: Valid for function string number undifined Boolean object, note that the return value is a string.

But null, array detects an object.

2,instanceof: Used to detect whether the object is an instance of a particular class, the return value is a Boolean value, preferably with the typeof (typeof value is an object with the instanceof for further determination). The inheritance chain can also be used to determine whether an object has been inherited.

3 . Object. Constructor: Function,string,number,boolean,object,array can be detected. But null,undefined error.

4,Object.prototype.toString.call (object): can detect the above various types, but do not know whether you can detect the inheritance of those classes, and will not inherit.


Hope that the cattle people greatly answer, exchange.

Reference: http://www.nowamagic.net/librarys/veda/detail/1250

This article is from the "Echo and you take off" blog, please be sure to keep this source http://5052416.blog.51cto.com/5042416/1684752

JS judging the type of object

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.