Home > Web Front-end > JS Tutorial > body text

js method to determine object type_javascript skills

WBOY
Release: 2016-05-16 17:54:40
Original
894 people have browsed it
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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template