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*

29
  • 151
    This answer is incorrect. typeof returns 'object' for null, which is not an object, and instanceof doesn't work for objects created using Object.create(null). Commented Apr 8, 2014 at 21:12
  • 3
    typeof null... object! Commented Sep 15, 2014 at 19:14
  • 24
    Arrays will also return as "objects" as in: someArray instanceof Object //true or typeof someArray === 'object' // true. What about: Object.prototype.toString.call(someObject) === "[object Object]", or "[object Array]" if you're trying to detect an array? Commented Jun 19, 2015 at 14:52
  • 9
    @Jonathan, there are better reasons for downvoting my answer, do you by chance have military background? :) Commented Sep 8, 2015 at 11:54
  • 10
    This should not be the accepted answer. Beyond the stylistic concerns raised by Jonathan, it is simply incorrect and does not bring up the very important subtleties in e.g. @matt-fenwick's answer. Commented Jan 18, 2016 at 20:27