In JavaScript, we can use the "window.location" object to redirect the browser to a different URL.
The "window.location" object represents the current URL of the browser, and by assigning a new URL to its href property, we can trigger a redirection.
// Redirect to a new URL window.location.href = "https://www.url-example.com";
This code will cause the browser to navigate to the specified URL (https://www.url-example.com in this case).
You can also use other properties of the window.location object to manipulate the browser's navigation, such as window.location.replace(url) or window.location.assign(url).
These methods perform a URL redirection similar to setting window.location.href.
// Redirect to a new URL using replace window.location.replace("https://www.url-example.com");
The key difference between replace and assign is that replace removes the current URL from the browser's navigation history, meaning that clicking the "Back" button won't take the user back to the original page.