Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

IDBVersionChangeEvent.oldVersion — the previous IndexedDB database version

The IDBVersionChangeEvent.oldVersion property exposes the previous version number of an IndexedDB database. In an upgradeneeded event, it helps select the required migrations; 0 means that the database did not previously exist.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

event.oldVersion

IDBVersionChangeEvent inherits from Event and carries IndexedDB database version information. Its read-only IDBVersionChangeEvent.oldVersion property contains the previous version number as a JavaScript number, not a string or a BigInt.

The upgradeneeded event on an IDBOpenDBRequest uses this interface when opening a database requires creating it or increasing its version. If the database did not previously exist, event.oldVersion is 0. In a migration handler, separate conditions such as event.oldVersion < 1 and event.oldVersion < 2 allow every missing step to run, including when intermediate versions are skipped.

Do not confuse oldVersion with newVersion: the former describes the previous version, the latter the target version. The example only constructs synthetic events, so it neither performs a migration nor proves that a database upgrade succeeded. This is a browser API, not an ECMAScript language feature; constructor availability must be checked separately from support for the property itself.

Examples

(() => {
  const firstCreation = new IDBVersionChangeEvent("upgradeneeded", {
    oldVersion: 0,
    newVersion: 3,
  });
  const upgrade = new IDBVersionChangeEvent("upgradeneeded", {
    oldVersion: 2,
    newVersion: 3,
  });

  console.log(firstCreation.oldVersion);
  console.log(upgrade.oldVersion);
})();

Result

0
2

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources