JS determine object type method _javascript skill

Source: Internet
Author: User
1, typeof
Supports basic types of acquisition, such as Boolean, string, number, function, object, undefined
Usage:
var v = true;//"string",
typeof V; Boolean
Ps:array/date/null are object,undefined for undefined.
2, instanceof
When you determine whether a value is a function or object, you can use instanceof to learn more about it
Usage:
var v = new Date ();
V instanceof object;//true
V instanceof date;//True
3, constructor
A more one-step method than instanceof, a constructor property.
var v = new Date ();
V.constructor = = Object;//true Note that the right side of the equals sign is the constructor of the type to be detected
V.constructor = = Date;//true

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.