I believe confidence is the result of writing successful code. "Successful" does not have to equal "quality" in the early stages of your development...if just means that you've been able to solve the problem to the satisfaction of your sponsor. As you amass successes throughout your coding career, your confidence level rises, because you have been able to meet the challenges presented to you, and, more importantly, identify those areas where you feel less comfortable about your selected approach or wish that you had the time to do something over in a different way.
I've come across many different levels of developer in my career. There are those developers who try to impress you with their latest clever solution to a simple and straightforward problem. There are also those developers who use twenty lines of code where three will do. There are those developers who immediately dismiss "old technology" and only look toward the latest and the greatest. There are also those developers who refuse to evolve with technology and stick to what they know because it's always worked for them.
This industry is about change...plain and simple. You have to embrace learning in order to be able to translate your ideas into results. You have to be willing to accept some amount of change in your habits, in your approach, and in your thinking as you progress throughout your career. You also have to be willing to reject the notion of change for change's sake...everything you do, every decision you make, every line of code you produce has to increase the overall value of whatever project you are on. All of these notions together can make you a better developer, and, as your skill improves, so will your confidence.