Well in simple terms, the rule of supply and demand applies to currencies as well.
When a government overspends money meaning it spends money that it doesn't have, then it has to start printing money to pay for the over budget costs. This is called Government Debt which is a result of budget deficit. By doing that, there is an increase in supply side of that currency which in absence of mutual demand in the international market will decrease its value. That's why budget deficit is a bad thing that every government should avoid.
Now in case of US, ever since WWII or even earlier, the government has been spending like crazy and that is exactly how it has been able to fund mega projects like Apollo program or build such a massive army. It has been spending the money it did not have:
currently its debt is larger than the size of its economy. Any other country in the same situation would see its currency value drop to worthless.
But a wise move that US did was to offer protection to Saudi Arabia when they felt threatened by Soviet Union in exchange of SA selling all its oil in US dollars. Besides that, after WWII, US and Canada were the only industrial countries that had remained out of harm and had full scale industries so there was a great demand for their products and while the rest of the big economies of pre WWII like Britain, Germany and France were in shambles, US dollar became the preferred currency for international trade and ever since US has been very diligent to keep it that way.
Now what it does is that it creates the international demand that can balance US government money printing. The fact that countries like yours need to buy US dollars to be able to make international procurement guarantees there would always be a demand for US Dollar.
I personally believe that one of the reasons that Obama was wise enough to reach a deal with Iran was the above. With the sanctions in place Iran, Russia, Cuba and China were more motivated to move away from the US Dollar for their exchange, and who knows, other countries might had gradually join them and eventually, demand for US dollar would decrease and then it value would drop to where it should be.