JsUnit (http://www.jsunit.net/) is a great tool for unit testing your JavaScript code. Te best part is that it can be integrated with build process for continuos integration. This helps to identify the errors at a early stage of development rather than waiting till the code has reached QA.
QUnit (http://docs.jquery.com/QUnit) is another unit testing from jQuery stable. All jQuery libraries are tested using qUnit. I have not yet included this as part of build but as per their documentation it can be integrated into browser automation tools like Selenium or Mercury.