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.
2 of 4
updated link + added updated way in underscore.js to determine object
Daan
  • 8k
  • 5
  • 47
  • 54

The official underscore.js uses this check to find out if something is really an object

// Is a given variable an object?
_.isObject = function(obj) {
  return obj === Object(obj);
};

UPDATE

The updated underscore.js library is now using the following, because of a previous bug in V8 and minor micro speed optimization.

// Is a given variable an object?
_.isObject = function(obj) {
  return typeof obj === 'function' || (typeof obj === 'object' && !!obj);
};
Daan
  • 8k
  • 5
  • 47
  • 54