DEV Community

loading...

Discussion on: 💡 How to check if a variable is undefined in JS

Collapse
jesperhoy profile image
Jesper Høy

I was too quick - what I meant was:

In other words - it works when qualified (if not in browser global scope, replace "window" with whatever xyz belongs to).

I have done this countless times and never thought to use typeof - which is why I felt the need to comment :-)

Thread Thread
benjaminmock profile image
Benjamin Mock Author

I see - but this is different. You're trying to access a non-existent property on a global object. That's of course not throwing a "Reference not defined" error, that's true.