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*

27
  • 83
    Functions are also objects and should be included in your check. Commented Dec 21, 2012 at 18:25
  • 5
    In this case would yourVariable !== null be better practice? Commented May 23, 2013 at 15:59
  • 12
    @RightSaidFred Seems that typeof null == 'object' will not be fixed in ES6. They said: This proposal has been rejected. It was implemented in V8 but it turned out that it broke a lot of existing sites. In the spirit of One JavaScript this is not feasible. Commented Sep 3, 2013 at 10:50
  • 18
    @Tresdin The best way is to run Object.prototype.toString.call(yourVar), being yourVar what you need to inspect. In case of arrays, Object.prototype.toString.call([1,2]) returns [object Array] Commented Feb 25, 2016 at 9:48
  • 28
    Downvoted because an array is also considered an object, so you should also check Array.isArray(yourVariable). Commented Nov 29, 2017 at 22:34