The book contains a lot of code, downloadable from this page. The all-in-one zip contains all the code for each chapter, as per the end of the chapter. To download each and every code listing, see the Git repositories at the bottom of this page.
You are free to use the code from this book however you wish. All code is licensed under the two clause BSD license.
If you want to code along with the examples in the book — and I highly recommend you do — you can download the initial project state for the TDD project chapters (11-15) below. Also see resources for the versions of various open source libraries used in the book.
Some details like refactorings are lost in the zip. For more fine-grained access to the code, there are Git repositories for each chapter, where you will find each and every code listing as separate commits.
git clone http://tddjs.com/code/01-automated-testing.git
git clone http://tddjs.com/code/02-the-tdd-process.git
git clone http://tddjs.com/code/03-tools-of-the-trade.git
git clone http://tddjs.com/code/04-test-to-learn.git
git clone http://tddjs.com/code/05-functions.git
git clone http://tddjs.com/code/06-applied-functions-and-closures.git
git clone http://tddjs.com/code/07-objects-and-prototypal-inheritance.git
git clone http://tddjs.com/code/08-ecmascript-5.git
git clone http://tddjs.com/code/10-feature-detection.git
git clone http://tddjs.com/code/11-the-observer-pattern.git
git clone http://tddjs.com/code/12-abstracting-browser-differences-ajax.git
git clone http://tddjs.com/code/13-streaming-data-with-ajax-and-comet.git
git clone http://tddjs.com/code/15-tdd-and-dom-manipulation-the-chat-client.git
git clone http://tddjs.com/code/17-writing-good-unit-tests.git