Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
4 of 4
Formatting. The link to the updated version of underscore.js linked to the master branch, which could misalign the line anchors in the URL in future versions
Gust van de Wal
  • 5.3k
  • 1
  • 27
  • 52

underscore.js provides the following method to find out if something is really an object:

_.isObject = function(obj) {
  return obj === Object(obj);
};

UPDATE

Because of a previous bug in V8 and minor micro speed optimization, the method looks as follows since underscore.js 1.7.0 (August 2014):

_.isObject = function(obj) {
  var type = typeof obj;
  return type === 'function' || type === 'object' && !!obj;
};
Daan
  • 8k
  • 5
  • 47
  • 54