Expert Developer JavaScript Question:
Can you use x === "object" to test if x is an object?

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"));
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"));
Previous Question | Next Question |
What happens when you don't declare a variable in Javascript? | What is the use of isNaN function? |