0

I thought my object detection would work:

if (Notification!=undefined) {}

However my JavaScript log is still showing the following error:

Uncaught ReferenceError: Notification is not defined

How do I properly do object detection for the Notification object?

No frameworks.

0

1 Answer 1

9

You can use typeof like so:

if (typeof Notification !== 'undefined') {

}

If you use typeof, it does not try to actually use the variable (which breaks and throws an error)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.