How can test driven development help you to create and debug your code?

How can test driven development help you to create and debug your code?