It depends on what you mean with "is an object". If you want everything that is not a *primitive*, e.g. things that you can set new properties on, this should do the trick:
function isAnyObject(value) {
return value != null && (typeof value === 'object' || typeof value === 'function');
}
It excludes the primitives (plain numbers/`NaN`/`Infinity`, plain strings, `true`/`false`, `undefined` and `null`) but should return true for everything else (including `Number`, `Boolean` and `String` objects). Note that JS does not define what "host" objects, such as `window` or `console`, should return when used with `typeof`, so those are hard to cover with a check like this.
If you want to know whether something is a "plain" object, e.g. it was created as a literal `{}` or with `Object.create(null)`, you might do this:
function isPlainObject(value) {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
} else {
var prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.prototype;
}
}