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.