There are some approaches which can help:
Unit testing
Write unit tests where possible. Solely relying on manual testing or finding bugs in the wild is hit-and-miss.
Use frameworks
Rather than rolling your own and risking the introduction of bugs, use established frameworks where possible.
Prefer CSS/high-level languages
Where you can cede functionality to CSS or whatever high-level language you're writing in.
Refactor
Refactor to reduce the amount of code. Less code = less places for things to go wrong.
Reuse
Re-useReuse existing code where you can. Even if code isn't an exact match, it can be better to copy, paste and modify rather than writing something afresh.
IDEs
Modern IDEs generally have at least some Javascript support. Some text editors are also Javascript aware.