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.

John
  • 1
  • 13
  • 98
  • 177

1 Answers1

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)

Tuvia
  • 859
  • 4
  • 15