Example 1 — Basic Read
Beginner example for window.history.
console.log(typeof window.history.length);
console.log(window.history.length >= 1); How It Works
- Step. length counts session history entries.
- Step. At least one for the current page.

window.history is the History object for this tab. Use history.back(), forward(), and go() to move through entries.
Read window.history with no parentheses.
window.history; | Call | What it does |
|---|---|
window.history | Session history for this tab. |
Window property in browsers. No import required.
| Parameter | Description |
|---|---|
| window.history | Read-only or assignable depending on the property. No function arguments. |
| Return Value | Description |
|---|---|
| * | Session history for this tab. |
Beginner example for window.history.
console.log(typeof window.history.length);
console.log(window.history.length >= 1); Beginner example for window.history.
console.log(window.history === history);
console.log(typeof history.back); Beginner example for window.history.
console.log(typeof history.pushState); window.history is a standard Window property in browsers.
Available in all modern browsers. Not used in plain Node.js without a DOM.
Bottom line: Safe in browsers. Skip in server-only Node scripts.
Continue through the Window properties list.
CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
9 people found this page helpful