instanceof与typeof

都会返回类型信息,但installedof与内存中的比较typeof与字符串比较

//objects
  var Person = function() {}

  var gary = new Person();

  console.log(typeof(gary)); // "object"
  gary instanceof Person // true

  //literals
  var str = 'hello world';
  console.log(typeof(str)); // "string"
  str instanceof String // False

  var str1 = new String('hello world');
  console.log(typeof(str1)) // "object"
  str1 instanceof String // true 

  

原文地址:https://www.cnblogs.com/xiaqi/p/4545417.html