一、

 基本数据类型:字符串、数字、布尔、Null、Undefined、symbol(ES6)
 引用数据类型:对象、数组、Function等。

 二、typeof它返回值是一个字符串,该字符串说明运算数的类型。

typeof (123) //"number"
typeof ("123") // "string"

typeof (true) // "boolean"

typeof (Symbol()) // "symbol"

typeof (undefined) // "undefined"
typeof (a) // "undefined" a未定义

typeof (function(){}) // "function"

typeof ({}) // "object"

typeof ([])  // "object"
typeof (null) // "object"

三、正确的判断数据类型(通用方法)

Object.prototype.toString.call(123); // "[object Number]"
Object.prototype.toString.call("123"); // "[object String]"
Object.prototype.toString.call(true); // "[object Boolean]"
Object.prototype.toString.call([]); // "[object Array]"
Object.prototype.toString.call(function(){}); // "[object Function]"
Object.prototype.toString.call(undefined); // "[object Undefined]"
Object.prototype.toString.call(null); // "[object Null]"
Object.prototype.toString.call(new Date()); // "[object Date]"
Object.prototype.toString.call(/^1$/); // "[object RegExp]"
Object.prototype.toString.call(new Error()); // "[object Error]"

 

四、instanceof运算符用来判断一个构造函数的prototype属性所指向的对象是否存在另外一个要检测对象的原型链上

  【类型判断】

[] instanceof Array // true
new Date instanceof Date // true
function(){} instanceof Function // true

 

附:

原型链:https://www.cnblogs.com/DF-fzh/p/5619319.html

 






posted on 2018-01-24 15:23  鱼之龙  阅读(135)  评论(0编辑  收藏  举报