DEV Community

Discussion on: JavaScript Interview Question #40: What is the type of `undefined` in JS?

Collapse
 
rohithv07 profile image
Rohith V

So, typeof always returns a string and if we do a check like

typeof undefined === undefined
Enter fullscreen mode Exit fullscreen mode

it is actually checking whether the string undefined equal to the type undefined which is a false.
Instead if we do

typeof undefined === "undefined"
Enter fullscreen mode Exit fullscreen mode

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.

Collapse
 
coderslang profile image
Coderslang: Become a Software Engineer

Yes, you're absolutely right