0

I'm checking over my code for uses of == instead of ===, but changing this line:

if(window.location == 'app:/test.html')

To this:

if(window.location === 'app:/test.html')

Results in the block no longer being executed.

What is the correct approach?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134

1 Answers1

2

The reason for this is because === matches the type as well as the contents.

window.location acts like a string in most cases, but is actually a Location object.

You can change your if to check the href property, which is a string:

if(window.location.href === 'app:/test.html')

Your code will then work as intended!

MDN has a decent article about window.location that's worth a read.

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134