What's the output?
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
In JavaScript, the typeof
operator always returns a string.
So, even though typeof undefined
evaluates to undefined
, it’s a string and not the primitive undefined
value.
The string ’undefined’
is not equal to the value undefined
.
ANSWER: the message false
will appear in the console.
Top comments (5)
So, typeof always returns a string and if we do a check like
it is actually checking whether the string undefined equal to the type undefined which is a false.
Instead if we do
we will get true as we are comparing with the string "undefined" and with the result which is a string we get from
typeof undefined
.Yes, you're absolutely right
If
typeof(undefined) == undefined
, that'd meanundefined
has no type, so it makes sense for the string"undefined"
to be returned instead :DHold on,
typeof null
is coming right after you :)Hey, I never claimed JavaScript is a sane language overall :D