History

history.back

Causes the browser to move back one page in the session history, equivalent to clicking the browser's back button

Syntax

JavaScript
history.back()

Return Value

undefined

Examples

Basic Usage
const backBtn = document.querySelector('.back-btn')!
backBtn.addEventListener('click', () => {
  history.back()
})
Practical Example
function goBackOrHome() {
  if (history.length > 1) {
    history.back()
  } else {
    window.location.href = '/'
  }
}
Advanced Usage
document.addEventListener('keydown', (e) => {
  if (e.altKey && e.key === 'ArrowLeft') {
    history.back()
  }
})

Understanding history.back

The history.back method in JavaScript causes the browser to move back one page in the session history, equivalent to clicking the browser's back button. It belongs to the History object and is one of the most widely used methods for working with history values in modern JavaScript and TypeScript applications.

The method signature is history.back(). When called, it returns undefined. Understanding when and how to use back() helps you write more expressive, readable code.

Common use cases for history.back include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like history-forward, history-go, history-pushstate, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for history.back is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More History Methods

Other methods in the History object

Related Tools

More History Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.