Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 700
pencilCake Avatar asked Oct 02 '09 15:10

pencilCake


People also ask

Which word is not reserved in JavaScript?

The NaN , Infinity , and undefined are not reserved keywords in JavaScript But you must avoid using them. They are properties of the global object and have special meanings.

What is event keyword in JavaScript?

When an event attribute is set, an implicit Function is created with event as the first argument. When the event fires, the event object is passed to that function.

What is a reserved word examples?

Often found in programming languages and macros, reserved words are terms or phrases appropriated for special use that may not be utilized in the creation of variable names. For example, "print" is a reserved word because it is a function in many languages to show text on the screen.


1 Answers

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

like image 155
Locksfree Avatar answered Oct 18 '22 17:10

Locksfree