zoukankan      html  css  js  c++  java
  • 【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
  • 相关阅读:
    poj 4005 Moles
    牛客 2C 圈圈
    牛客 2B 树 (组合计数)
    AC日记——校门外的树(增强版) 洛谷 P1276
    AC日记——寻找道路 洛谷 P2296
    AC日记——挤牛奶 洛谷 P1204
    AC日记——最大数 洛谷 P1198 [JSOI2008]
    AC日记——中位数 洛谷 P1168
    AC日记——校门外的树 洛谷 P1047
    AC日记——约瑟夫问题 codevs 1282
  • 原文地址:https://www.cnblogs.com/allearner/p/5058735.html
Copyright © 2011-2022 走看看