Exactly! And if you ever run into scenarios like login/logout flows—where going back just doesn’t make sense—there’s an even cleaner approach.
That’s where window.location.replace() really shines. It navigates just like the others, but it doesn’t keep the current page in the session history.
window.location.replace("https://example.com");
Perfect for those situations when you want to replace the current view without giving the user a way to go back. From a security or UX standpoint, this can be the smartest “javascript go to url” method in your toolkit.