Avatar ·

How to make a redirect to another web page in JavaScript?

Hello everyone! I just started learning JavaScript and encountered this task: after a user clicks a button or after a successful form submission, I need to redirect them to another page. For example, after registration — to a welcome page, or after logging out — to the homepage. I tried using `window.location`, but I don't fully understand how it works correctly. Here's my code: ```javascript function redirect() { window.location = "https://example.com"; } ``` But sometimes it works and sometimes it doesn't. I also saw that people use `window.location.href`, `window.location.replace`, and even `window.location.assign`. What's the difference between them? Which method is best for a simple redirect? I'm also interested in: how to make a redirect with a delay, so that first...