Is there a difference between window.addeventlistener and addeventlistener?

Asked

Viewed 871 times

3

When I use addEventListener is the same as window.addEventListener or there is a difference?

  • As far as I know, it’s a matter of reference, window you are referring to the window itself. But I may be wrong.

  • window takes the whole window, up to where you type the URL, Document you take the document only, the website.

  • You mean addeventlistener without the point refers to Document?

  • Exactly, it’s the same user thing document

1 answer

6


None, they are the same thing. It is a method of window made available in the global scope.

All methods/properties of window are in the global scope and can be accessed via object: window.location.href or directly location.href. There are hundreds...

  • Where do you find this most technical javascript information?

  • @Moraisvilson you can do on the console console.log(Object.keys(window)); and you will see all properties/methods. For more technical documentation you can always use MDN: https://developer.mozilla.org/en-US/docs/Web/API/Window

Browser other questions tagged

You are not signed in. Login or sign up in order to post.