js method to determine object type_javascript skills
- WBOYOriginal
- 2016-05-16 17:54:40917browse
1. typeof
supports the acquisition of basic types, such as: boolean, string, number, function, object, undefined
Usage:
var v = true;//"string",
typeof v; //boolean
PS: Array/Date/null, etc. are all objects, undefined is undefined
2, instanceof
When determining whether a value is a function or object , you can use instanceof to learn more details
Usage:
var v = new Date();
v instanceof object;//true
v instanceof Date;// true
3. constructor
A more one-step method than instanceof, constructor attribute.
var v = new Date();
v.constructor == Object;//true Note that the right side of the equal sign is the constructor of the type to be detected
v.constructor == Date;//true
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn