js data types Basic data types: number, string, boolean, undefined, null, Symbol, Reference data type: object
Basic data types except null can be judged by typeof, and reference data types except Function return Object let a = 1, b = '2', c = true, d = undefined, e = null, f = Symbol('f'), g = function () {}, h = [], i = new Date() console.log(typeof a) console.log(typeof b) console.log(typeof c) console.log(typeof d) console.log(typeof e) console.log(typeof f) console.log(typeof g) console.log(typeof h) console.log(typeof i) View the output You can see that the typeof of null is object. This is a historical bug. If you are interested, you can refer to "The history of "typeof null"" You can use the following method to determine null function checkNull(num) { return num === null } The detailed type of object can be determined by Object.prototype.toString.call() function checkObject(obj) { return Object.prototype.toString.call(obj) } console.log(checkObject(g)) console.log(checkObject(h)) console.log(checkObject(i)) You can see the output results It can also be judged by the constructor constructor() console.log(g.constructor === Function) console.log(h.constructor === Array) console.log(i.constructor === Date) You can see the output results Summarize This is the end of this article about js data types and their judgment methods. For more relevant js data types and judgment content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL and MySQL Workbench Installation Tutorial under Ubuntu
>>: How to build php7 with docker custom image
MySQL is a relatively easy-to-use relational data...
Table of contents 1. Boolean 2. Expression 3. Mul...
When making a web page, we usually need to consid...
1. Conclusion Syntax: limit offset, rows Conclusi...
MySQL 5.7 and above versions provide direct query...
The default storage directory of mysql is /var/li...
This article example shares the specific code of ...
Preface The reason why MySQL's innodb engine ...
What is a descending index? You may be familiar w...
1. Brief Introduction Vue.js allows you to define...
Modify the group to which a user belongs in Linux...
The process packets with the SYN flag in the RFC7...
Table of contents 1. Introduction to Nginx 2. Ima...
1. Understanding the meaning of web standards-Why...
When joining a Windows 2008 server subdomain to a...