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!
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.
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.
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.
It is not a reserved keyword, but it is a global variable in IE at least.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With