|
@@ -0,0 +1,55 @@
|
|
|
+<!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>
|
|
|
+ var arr = [1,2,3,4];
|
|
|
+ var obj = {
|
|
|
+ name:"Lucy",
|
|
|
+ age:10
|
|
|
+ }
|
|
|
+ var fn1 = function() {
|
|
|
+ console.log("你好")
|
|
|
+ }
|
|
|
+ // 1.typeof
|
|
|
+ console.log(typeof 1);//number
|
|
|
+ console.log(typeof "1"); //string
|
|
|
+ console.log(typeof true); //boolean
|
|
|
+ console.log(typeof undefined); //undefined
|
|
|
+ console.log(typeof null); //object
|
|
|
+ console.log(typeof arr);//object
|
|
|
+ console.log(typeof obj);//object
|
|
|
+ console.log(typeof fn1);//function
|
|
|
+
|
|
|
+
|
|
|
+ // 2.instanceof
|
|
|
+ console.log(obj instanceof Object);
|
|
|
+ console.log(arr instanceof Object);
|
|
|
+ console.log(fn1 instanceof Object);
|
|
|
+
|
|
|
+ // 3.Object.prototype.toString.call()
|
|
|
+ console.log(Object.prototype.toString.call(1));
|
|
|
+ console.log(Object.prototype.toString.call("哈哈"));
|
|
|
+ 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((1).constructor === Number);
|
|
|
+ console.log("哈哈".constructor === String);
|
|
|
+ console.log(false.constructor === Boolean);
|
|
|
+ // console.log(null.constructor === Object);
|
|
|
+ // console.log(undefined.constructor === undefined);
|
|
|
+ console.log(obj.constructor === Object);
|
|
|
+ console.log(arr.constructor === Object);
|
|
|
+ console.log(fn1.constructor === Object);
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|