Last Updated: 21 Nov 2020
Namespace Your Code
Return null, not false
null, you should always use that instead of
false to return a 'no data found' indication in a function. There is a temptation to return
false should be reserved for functions that return only true or false.
null is more correct.
This is no different than any other language, but is still a mistake that is easy to make.
Using Optional Parameters & Default Arguments
If you need to create a function with optional parameters and defaults for those parameters that aren't specified, see Optional Parameters and Default Arguments.
Using Classes & the 'this' keyword
this keyword, because I'm not instantiating objects. The context of
this can change fairly easily, especially if you're working with someone else's framework (e.g. YUI), and is an easy source for frustration or errors. That said, there are some cases when creating a class really is the best option for managing data. No harm in doing that, and we can look forward to a better implementation in JS 2.0.
<script> tag (linking to your JS code) at the beginning of the document and then attach event listeners (onclick, onchange, etc.) programatically, rather than via the
onchange attributes of the documents DOM elements. Wikipedia has a good summary on the topic, and Christian Heilmann has a good how-to article.