JavaScript Method Names

I’ve been working on a new website for my company recently, and ran across an annoying issue with a JavaScript method name I was using to handle a mouse over event.  I usually define my methods with generic names and then rename them to fit their specific purpose once I have a better understanding of how I will use them in my code.

In this particular case, I named the method “MouseOver”.  However, when I ran the page, nothing happened – the method was never called, and no error was given.  This was pretty annoying, but a quick check by a second pair of eyes spotted that MouseOver was apparently a reserved keyword. 

There are a number of websites that list reserved words for JavaScript.  None of them list MouseOver (not to be confused with OnMouseOver, which is an existing method name that should be avoided), so this is my small addition to these lists – avoid MouseOver as a function name, as the behavior will apparently be undefined.

Comments are closed.