Test typeof vs Test ! vs Test if prototype vs Test instanceof vs Underscore

Edit on GitHub

Check if it is an object

Setup

var obj = {};

Tests

  • Test typeof

    typeof obj === 'object'
  • Test !

    !! obj
  • Test if prototype

    obj && obj.prototype
  • Test instanceof

    obj instanceof Object
  • Underscore

    var type = typeof obj;
    type === 'function' || type === 'object' && !!obj;