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.

5
  • 2
    Why the string comparison, why not simply item.constructor === Object? Commented Feb 27, 2016 at 23:20
  • null throws an exception Uncaught TypeError: Cannot read property 'constructor' of null(…) Commented May 17, 2016 at 14:08
  • @rounce I am aiming to support older IE versions, why does it not work in IE? Because of the indexOf or because of constructor.name? Commented Jan 24, 2018 at 14:15
  • This will fail with undefined too. Commented Oct 28, 2020 at 14:17
  • if your variable can't have falsy value varName && varName.constructor.name === "Object" if your variable may have falsy value varName != null && varName != undefined && varName.constructor.name === "Object" Commented Mar 31, 2022 at 8:09