toString、valueOf() 、typeof 方法、instanceof方法 typeof 方法 instanceof方法   toString()方法 valueOf()方法

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/typeof

typeof操作符返回一个字符串,表示未经计算的操作数的类型。

toString、valueOf() 、typeof 方法、instanceof方法
typeof 方法
instanceof方法
 
toString()方法
valueOf()方法

下表总结了typeof可能的返回值。有关类型和原始值的更多信息,可查看 JavaScript数据结构 页面。

类型 结果
Undefined "undefined"
Null "object"(见下文)
Boolean "boolean"
Number "number"
String "string"
Symbol (ECMAScript 6 新增) "symbol"
宿主对象(由JS环境提供) Implementation-dependent

函数对象([[Call]] 在ECMA-262条款中实现了)

  new Function()
  function(){}、
  class C{}、
  Math.sin

"function"

任何其他对象

  Array、Data、{}、[]

  new Date()、
  new Boolean(true)
  new Number(1)
  new String("abc")

"object"

instanceof方法

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/instanceof

instanceof运算符用于测试构造函数的prototype属性是否出现在对象的原型链中的任何位置

用来检测 constructor.prototype 是否存在于参数 object 的原型链上。

toString、valueOf() 、typeof 方法、instanceof方法
typeof 方法
instanceof方法
 
toString()方法
valueOf()方法

// 定义构造函数
function C(){} 
function D(){} 

var o = new C();


o instanceof C; // true,因为 Object.getPrototypeOf(o) === C.prototype


o instanceof D; // false,因为 D.prototype不在o的原型链上

 

toString()方法

https://www.cnblogs.com/xiaohuochai/p/5557387.html

toString()方法返回反映这个对象的字符串

 

valueOf()方法

https://www.cnblogs.com/xiaohuochai/p/5560276.html

1.如果存在任意原始值,它就默认将对象转换为表示它的原始值,原始值请参考https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Data_structures#%E5%8E%9F%E5%A7%8B%E5%80%BC(_primitive_values_)

2.对象是复合值,而大多数对象无法真正表示为一个原始值,因此默认的valueOf()方法简单地返回对象本身,而不是返回一个原始值