In JavaScript, The assign() method of the Location object can be used to navigate to a new web page.

Here is an example:

location.assign(`https://attacomsian.com/protips`);

The replace() method is another way to load a new web page in JavaScript. It works similar to assign() except that it simulates an HTTP redirect and doesn't create an entry in the browser's history. It means that the user won't be able to use the back button to navigate back to the original document:

location.replace(`https://attacomsian.com/protips`);

Finally, the last way to redirect the user to another web page is by using the location.href property. It resembles the user's click event and produces the same effect as using the assign() method:

location.href = `https://attacomsian.com`;

Take a look at JavaScript location object tutorial to learn more about the Location object properties and methods.

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.