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.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 1
    best answer! works for many of cases mentioned here Commented Oct 20, 2017 at 8:57
  • 1
    Because this returns false for isObject(myDateObject), this is not an answer to the question. It does not tell if a variable is an object, only if it is an object of a specific class. The question here is for a generic function that returns true for any object. Commented Jan 13, 2018 at 19:09
  • @Yetanotherjosh It is an answer indeed 🤓 you mentioned case which is described in answer, and the point - you have to use isDate for yourDateObject with purpose to write robust code otherwise you will have brittle isObject method. Commented Jan 19, 2018 at 17:03
  • 1
    @VladimirKovpak Using Date in my comment was ill-chosen because yes, the answer does discuss Date. But Date is just one of infinite possible classes and the point holds for any other class. Example: class Foo() { }; var x = new Foo(); isObject(x) returns false. I don't know exactly what the OP's use case is, but it's easy to conceive of scenarios in which having to know about all possible classes and checking specifically against every one of them is going to be infeasible. Commented Jan 19, 2018 at 21:09
  • 1
    Using instanceof doesn't work for objects created from Object.create(null). Commented Feb 11, 2018 at 5:19