So, typeof always returns a string and if we do a check like
typeof undefined === undefined
it is actually checking whether the string undefined equal to the type undefined which is a false. Instead if we do
typeof undefined === "undefined"
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.
typeof undefined
Yes, you're absolutely right
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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