Check if a value is an object in JavaScript

Danny Fox picture Danny Fox · Dec 14, 2011 · Viewed 1.3M times · Source

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

Answer

Chuck picture Chuck · Dec 14, 2011

If typeof yourVariable === 'object', it's an object or null. If you want to exclude null, just make it typeof yourVariable === 'object' && yourVariable !== null.