| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <!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>
- /**
- * js的数据类型:
- * 基本数据类型
- * Null Undefined String Number Boolean
- * 引用数据类型
- * Object(函数 对象 数组)
- */
- var obj = { name: "图图" };
- var arr = [1, 2, 3, 4];
- function fn1() { return 1 };
- // // 1.typeOf()
- // console.log(typeof(1));
- // console.log(typeof("1"));
- // console.log(typeof(true));
- // console.log(typeof(undefined));
- // console.log(typeof(null));
- // console.log(typeof(obj));
- // console.log(typeof(arr));
- // console.log(typeof(fn1));
- //2. instanceof
- // console.log(obj instanceof Object)
- // console.log(arr instanceof Array)
- // console.log(fn1 instanceof Function)
- // 3.Object.prototype.toString.call(xxx)
- // console.log(Object.prototype.toString.call(1));
- // console.log(Object.prototype.toString.call("1"));
- // console.log(Object.prototype.toString.call(false));
- // console.log(Object.prototype.toString.call(null));
- // console.log(Object.prototype.toString.call(undefined));
- // console.log(Object.prototype.toString.call(obj));
- // console.log(Object.prototype.toString.call(arr));
- // console.log(Object.prototype.toString.call(fn1));
- // 4.constructor
- // null undefined无法判断
- console.log(false.constructor === Boolean);
- console.log('false'.constructor === String);
- console.log((21).constructor === Number);
- // console.log(null.constructor === Null);
- // console.log(undefined.constructor === Undefined);
- console.log(obj.constructor === Object);
- console.log(arr.constructor === Array);
- console.log(fn1.constructor === Function);
- </script>
- </body>
- </html>
|