history.go
Loads a page from the session history, identified by its relative location to the current page
Syntax
history.go(delta?)Parameters
| Parameter | Type | Description |
|---|---|---|
| delta | number | The position relative to the current page (negative goes back, positive goes forward) |
Return Value
undefined
Examples
history.go(-1) // Same as history.back()
history.go(1) // Same as history.forward()history.go(-2) // Go back two pagesfunction reload() {
history.go(0) // Reloads the current page
}Understanding history.go
The history.go method in JavaScript loads a page from the session history, identified by its relative location to the current page. 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.go(delta?). It accepts 1 parameter: delta. When called, it returns undefined. Understanding when and how to use go() helps you write more expressive, readable code.
Common use cases for history.go include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like history-back, history-forward, history-pushstate, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for history.go 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
history.backCauses the browser to move back one page in the session history, equivalent to clicking the browser's back button
history.forwardCauses the browser to move forward one page in the session history, equivalent to clicking the browser's forward button
history.pushStatePushes the given data onto the session history stack with the specified title and, if provided, URL
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.