The Back Button

Have you ever wondered about the back button you will find in every app? How does it work? If you say, it’s just saving every step you do and back one step at time. You are absolutely right. But sometimes I feel awkard when I can not get back to the page I previously visit. If I visit I should able back to it right? But sometimes not. I want to share with you why under the hood.

Let say you are typing urls and you want to undo to the previous one. What the program will do is insert every url you type before in to the array collection, and when you hit the back button it will back one step at a time.

We will see this in action using javascript.

The first thing is we need array to collect steps.

The example I pick is a web browser search bar and this are what you recentily visit.

function factorial(n) {
  if (n === 0) {
    return 1;
  }
  return n * factorial(n - 1);
}