Predict the output of the following javascript code
console.log(typeof null);
Quiz Explanation
In JavaScript, the typeof
operator is used to determine the data type of a variable or an expression. However, it has some quirks, one of which is its behavior with null
.
Surprisingly, when you use typeof
with null
, it returns "object"
. This behavior is often considered a mistake in the language, but it's too deeply ingrained to change now without breaking a lot of existing code. So, the output of the given code will be:
object