【JavaScript】之【Object】

见代码:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Object</title>
 6 
 7 </head>
 8 <body>
 9 <script type="text/javascript">
10     //        let obj = {};
11     //        let arr = [];
12     var obj = {};
13     var arr = [];
14 
15     console.log(typeof obj);//object
16     console.log(typeof arr);//object
17     console.log(typeof null);//object
18     console.log(typeof '');//string
19     console.log(typeof undefined);//undefined
20 
21     console.log('*******************************************');
22 
23     console.log(typeof obj === 'object');//true
24     console.log(typeof arr === 'object');//true
25     console.log(typeof null === 'object');//true
26     console.log(typeof '' === 'object');//false
27     console.log(typeof undefined === 'object');//false
28 
29     console.log('*******************************************');
30 
31     console.log("typeof obj === 'object':" + typeof obj === 'object');//false
32     console.log("typeof arr === 'object':" + typeof arr === 'object');//false
33     console.log("typeof null === 'object':" + typeof null === 'object');//false
34     console.log("typeof '' === 'object':" + typeof '' === 'object');//false
35     console.log("typeof undefined === 'object':" + typeof undefined === 'object');//false
36 
37     console.log('------------------优先级搞的鬼');
38 
39     console.log("typeof obj === 'object':" + (typeof obj === 'object'));//typeof obj === 'object':true
40     console.log("typeof arr === 'object':" + (typeof arr === 'object'));//typeof arr === 'object':true
41     console.log("typeof null === 'object':" + (typeof null === 'object'));//typeof null === 'object':true
42     console.log("typeof '' === 'object':" + (typeof '' === 'object'));//typeof '' === 'object':false
43     console.log("typeof undefined === 'object':" + (typeof undefined === 'object'));//typeof undefined === 'object':false
44 
45 
46     console.log('------------------优先级搞的鬼');
47     console.log(("typeof obj === 'object':" + typeof obj) === 'object');//false
48     console.log(("typeof arr === 'object':" + typeof arr) === 'object');//false
49     console.log(("typeof null === 'object':" + typeof null) === 'object');//false
50     console.log(("typeof '' === 'object':" + typeof '') === 'object');//false
51     console.log(("typeof undefined === 'object':" + typeof undefined) === 'object');//false
52     //"typeof obj === 'object':object“ === 'object' --------false
53 
54     console.log('*******************************************');
55 
56     console.log("Object.prototype.toString.call(obj) === '[object Object]':" + (Object.prototype.toString.call(obj)));//Object.prototype.toString.call(obj) === '[object Object]':[object Object]
57     console.log("Object.prototype.toString.call(arr) === '[object Object]':" + (Object.prototype.toString.call(arr)));//Object.prototype.toString.call(arr) === '[object Object]':[object Array]
58     console.log("Object.prototype.toString.call(null) === '[object Object]':" + (Object.prototype.toString.call(null)));//Object.prototype.toString.call(null) === '[object Object]':[object Null]
59     console.log("Object.prototype.toString.call('') === '[object Object]':" + (Object.prototype.toString.call('')));//Object.prototype.toString.call('') === '[object Object]':[object String]
60     console.log("Object.prototype.toString.call(undefined) === '[object Object]':" + (Object.prototype.toString.call(undefined)));// Object.prototype.toString.call(undefined) === '[object Object]':[object Undefined]
61 
62     console.log('*******************************************');
63     //严谨的判断Object方式:
64     console.log("Object.prototype.toString.call(obj) === '[object Object]':" + (Object.prototype.toString.call(obj) === "[object Object]"));//Object.prototype.toString.call(obj) === '[object Object]':true
65     console.log("Object.prototype.toString.call(arr) === '[object Object]':" + (Object.prototype.toString.call(arr) === "[object Object]"));//Object.prototype.toString.call(arr) === '[object Object]':false
66     console.log("Object.prototype.toString.call(null) === '[object Object]':" + (Object.prototype.toString.call(null) === "[object Object]"));// Object.prototype.toString.call(null) === '[object Object]':false
67     console.log("Object.prototype.toString.call('') === '[object Object]':" + (Object.prototype.toString.call('') === "[object Object]"));// Object.prototype.toString.call('') === '[object Object]':false
68     console.log("Object.prototype.toString.call(undefined) === '[object Object]':" + (Object.prototype.toString.call(undefined) === "[object Object]"));//Object.prototype.toString.call(undefined) === '[object Object]':false
69 
70 </script>
71 </body>
72 </html>
View Code

 

posted @ 2015-12-19 10:31  MShineRay  阅读(188)  评论(0编辑  收藏  举报