Search code examples
javascripteventsreserved-words

Is 'event' a reserved word in JavaScript?


I am a beginner to Javascript. And when I was practicing I have noticed something.

Take this function:

<script type="text/javascript">
    function showChar(sSomeData, oEvent)
    {
        alert (oEvent.keyCode);
        return true;
    }

</script>

When I call this function as this:

 <input type="text" id="txtTextBox" onkeypress="return showChar('some text', oEvent);" />

I get a JS error: "Microsoft JScript runtime error: 'oEvent' is undefined"

But if I rename oEvent with 'event' like:

<input type="text" id="txtTextBox" onkeypress="return showChar('some text', event);" />

Then it works fine. My conclusion is 'event'is a reserved word which stands for event argument in Java Script. But when I have checked the net I did not see 'event' as a reserved word.

Am I mistaken or it is not really documented as a reserved word?

Thanks!


Solution

  • It is not a reserved keyword, but it is a global variable in IE at least.