Expert Developer JavaScript Question:

Download Job Interview Questions and Answers PDF

Can you use x === "object" to test if x is an object?

Expert JavaScript Developer Interview Question
Expert JavaScript Developer Interview Question

Answer:

In short, yes, but you must take into account the fact that null is considered an object in JavaScript. Even if x is null, 'console.log(typeof x === "object")' will log true instead of false.
To account for this, you must also test whether or not x is null by including the following:
console.log((x !== null) && (typeof x === "object"));

Download Expert JavaScript Developer Interview Questions And Answers PDF

Previous QuestionNext Question
What happens when you don't declare a variable in Javascript?What is the use of isNaN function?