Manual:Writing testable JavaScript

Return values
Functions should always have a return value. Not just "get"-like functions, but also (perhaps even more important) the "set"-like functions. Scripts may not use this return value in many cases (ie. it's out of their scope to do anything about it), but in more advanced structures or test suites, the return value of a "set" function is very important (ie. "don't load X if Y was not set", or "Did the function correctly refuse to do X in scenario Y").

Compare the following two functions Compared to:

The latter is much easier to verify. For example, in the above case, a key may not be a number (such as an array index key). So to test that it refuses to do so in QUnit: