运算符 typeof 和 instanceof
-
-
识别函数
-
判断是否是引用类型(但是不能区分是那种引用类型)
(typeof "abc123"); // string (typeof 123); // number (typeof a); // undefined (typeof true); // boolean (typeof Symbol('fei')); // symbol (typeof function fei() {}); // function (typeof null); // object ***************************** (typeof []); // object (typeof {}); // object
([] instanceof Array) ? "ok" : "no"; // ok ([] instanceof Object) ? "ok" : "no"; // ok ({} instanceof Object) ? "ok" : "no"; // ok (null instanceof Object) ? "ok" : "no"; // no *****************************