Skip to content

Instantly share code, notes, and snippets.

@rafbm
Created August 25, 2012 11:34
Show Gist options
  • Save rafbm/3464186 to your computer and use it in GitHub Desktop.
Save rafbm/3464186 to your computer and use it in GitHub Desktop.
In most browsers, `event` is an ever-existing JavaScript variable which value changes depending on context

In most browsers, event is an ever-existing JavaScript variable which value changes depending on context.

Safari, Chrome and Opera:

<script>
  window.onload = function() {
    console.log(event) // Event (type: "load")
  }
  console.log(event) // undefined
</script>

Internet Explorer (tested 7 to 9):

<script>
  window.onload = function() {
    alert(event) // Event (type: "load")
  }
  alert(event) // null
</script>

Firefox:

<script>
  window.onload = function() {
    console.log(event) // ReferenceError: event is not defined
  }
  console.log(event) // ReferenceError: event is not defined
</script>

This means, if it wasn’t for Firefox, you wouldn’t have to declare an event or e argument for event handlers. You could safely declare function() and use event inside the function body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment