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
Preface The following are the ways to implement L...
1. Before configuring the IP address, first use i...
background Recently, I executed a DML statement d...
In this system, the # sign represents the root us...
Table of contents Set a not null constraint when ...
Pull the image docker pull season/fastdfs:1.2 Sta...
Table of contents 1. Baidu Map API Access 2. Usin...
Introduce two methods to view MySQL user permissi...
Let's briefly sort out the configuration of s...
query_cache_limit query_cache_limit specifies the...
To do MySQL performance adjustment and service st...
Table of contents 1. Rule 1: Object.Method() 1.1 ...
Preface Vuex allows us to define "getters&qu...
Table of contents Function Basic query functions ...
Table of contents background Inspiration comes fr...