When you change your URL, let suppose you have some issues with old domain or you want that your website you open with multiple domains like mywebsite.com, mywebsite.net, mywebsite.in. In such case, you have one website and multiple domains. People use this concept for marketing too.
Using 301 Redirect domain, a user as well as robots will be redirected to your new domain and your SEO ranking will also be transferred to this new domain. You have the option of redirecting via coding too but by this method, you SEO ranking will not be transferred to the new domain.
Tips to remember
Firstly redirect your domain with "301 Redirect" and then make your website live. Because if you have not setup 301 Redirect but you made your website live and Bots visit your website. Your website will be re-crawled again and will be treated as a new website and it will affect your actual ranking of previous domain.
This is a hard work if you have a website with many pages. If your website is SEO optimised and you changed your domain name, you have to change your internal linking also. Otherwise, your domain will be redirected to new URL but your internal links will still point to an old domain which can be harmful for your SEO ranking.