The History object is designed to store the history of web page visits in the browser. This object is available to us through the object Window.
All information about the visit of the user is stored in a special stack (history stack). Using the length property, you can find out how many web pages are stored on the stack:
document.write(window.history.length);
To move through the pages in history, the history object defines back() (move to the last viewed page) and forward() (move to the next viewed page) methods.
history.back(); // moving back history.forward();//move to next viewed page
The go() method allows you to move forward and backward through history by a certain number of pages:
history.go(-2);// let's move 2 pages back history.go(2);//let's move 2 pages forward