Not only that, but there’s an entire line of presidential succession. It’s part of a broader concept of ‘continuity of government’. Basically, it ensures that there’s always someone formally in charge. You could vaporize half the country including every senior official and there’d still be a legit, sworn in president in a few hours.
There’s basically contingencies upon contingencies. One interesting book on the topic is ‘Raven Rock’ by Garrett M. graff.