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:

function showChar(sSomeData, oEvent)
  {
  alert (oEvent.keyCode);
  return true;
  }

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 eventis a reserved word which stands for event argument in JavaScript. 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?


Solution

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