Answers

Question and Answer:

  Home  Expert JavaScript Developer

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

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"));

 210 views

More Questions for you: