How does js judge the type?
In this article, the editor introduces in detail "js how to judge the type", the content is detailed, the steps are clear, and the details are handled properly. I hope this "js how to judge the type" article can help you solve your doubts.
1. To judge the difference between reference type and basic type, you can use typeof to judge the basic type.
Typeof returns object in addition to the function returning function for reference types. However, the array we developed must return the array type, and typeof is not suitable for reference types.
Typeof 1 / / 'number'typeof' 1' / / 'string'typeof undefined / /' undefined'typeof true / / 'boolean'typeof Symbol () / /' symbol'typeof null / / 'object'
2. Instanceof is usually used to judge the reference type.
Var obj = {} var arr = [] var fun = () = > {} typeof obj / / 'object'typeof arr / /' object'typeof fun / / 'function'obj instanceof Object / / truearr instanceof Array / / truefun instanceof Function / / true here, the article "how to determine types in js" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, Welcome to the industry information channel.