When a Windows phone is turned on for the first time or right after a hard reset, you are prompted to sign in or create a Microsoft account. It will also ask if you want to restore from an existing backup (more later).
The phone can be backed up automatically or on demand to that account.
Those backups can be restored to another Windows phone the first time it is turned on or after it is hard reset.
It won't restore all the apps but it will restore settings for apps that allow that when they are reinstalled. And if the new phone has a different screen aspect ratio or a different version of Windows, expect to do some tweaking.
You will have to reinstall all but the default apps, so make a note of those before you start, particularly if you have a lot of apps you no longer keep on the phone. The app store keeps a list of apps you EVER had but not what you LAST had on your phone. Just check off the ones you want re-installed and go do something else for a while.
Mostly for security reasons, you will need to enter credentials for email, etc..
Your contacts and text history will automatically reappear since those are retained in the cloud but it might take minutes to days.