Skip to content
Fix Code Error

Check if a value is an object in JavaScript

March 13, 2021 by Code Error
Posted By: Anonymous

How do you check if a value is an object in JavaScript?

Solution

UPDATE:

This answer is incomplete and gives misleading results. For example, null is also considered of type object in JavaScript, not to mention several other edge cases. Follow the recommendation below and move on to other "most upvoted (and correct!) answer":

typeof yourVariable === 'object' && yourVariable !== null

Original answer:

Try using typeof(var) and/or var instanceof something.

EDIT: This answer gives an idea of how to examine variable’s properties, but it is not a bulletproof recipe (after all there’s no recipe at all!) for checking whether it’s an object, far from it. Since people tend to look for something to copy from here without doing any research, I’d highly recommend that they turn to the other, most upvoted (and correct!) answer.

Answered By: Anonymous

Related Articles

  • Ukkonen's suffix tree algorithm in plain English
  • Is CSS Turing complete?
  • How to properly do JSON API GET requests and assign output…
  • Get the name of an object's type
  • easiest way to extract Oracle form xml format data
  • What does do?
  • How to prevent scrolling the whole page?
  • Issue with iron-ajax request
  • What is the difference between typeof and instanceof and…
  • Nuxt: Cannot read property 'title' of undefined

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to return dictionary keys as a list in Python?

Next Post:

Check if table exists in SQL Server

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error