Debugging is the process of finding and fixing areas of problematic code. That is basically a dictionary definition of what debugging is, because debugging is much more than finding and fixing errors. You may have to debug an application because certain sections are slow and use too much processor power. You may have to debug a website because certain browsers render your file differently from what you want. You may even have to debug your file because it does not work with some other code (such as PHP or a web service) the way it should, and you can't change the other code because it may not be yours to change.
But the difference between debugging and writing good code is that you can't predict when and where you will have to debug, because you can't possibly know until you test the program. However, you can take some steps that may help you keep debugging to a minimum.