1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // Function Array Object ...
- var str = "hello";
- var num = 10;
- var boo = true;
- var arr = [1,2];
- var obj = {a:1};
- var foo = function(){console.log(1)};
- var und = undefined;
- var nu = null;
- // 方法一
- // console.log( typeof str );
- // console.log( typeof num);
- // console.log( typeof boo);
- // console.log( typeof arr);
- // console.log( typeof obj);
- // console.log( typeof foo);
- // console.log( typeof und);
- // console.log( typeof nu);
- // 方法二
- // instanceof 只能判断 object array function
- // console.log( arr instanceof Array );
- // console.log( obj instanceof Object );
- // console.log( str instanceof String );
- // console.log( foo instanceof Function );
- // 方法三
- // console.log(arr.constructor == Array)
- // console.log(str.constructor == String);
- // console.log(num.constructor == Number);
- // console.log(foo.constructor == Function);
- // console.log(obj.constructor == Object);
- // console.log(boo.constructor == Boolean);
- // 方法四
- // console.log( Object.prototype.toString.call(und) );
- // console.log( Object.prototype.toString.call(nu) );
- // console.log( Object.prototype.toString.call(str) );
- // console.log( Object.prototype.toString.call(num) );
- // console.log( Object.prototype.toString.call(foo) );
- // console.log( Object.prototype.toString.call(boo) );
- // console.log( Object.prototype.toString.call(arr) );
- // console.log( Object.prototype.toString.call(obj) );
- </script>
- </body>
- </html>
|