Home

SessionStorage

SessionStorage is a component of the Web Storage API that provides a per-tab key-value storage area for the duration of a browsing session. Data stored in sessionStorage persists across page reloads and restores within the same tab, but is cleared when the tab or its browsing context is closed. Each tab typically has its own sessionStorage, and the data is scoped to the same origin, meaning it is not shared with other tabs or windows.

The API consists of setItem, getItem, removeItem, clear, a length property, and key(index) to enumerate keys.

Lifecycle and scope: SessionStorage lasts for the lifetime of the tab’s session. It is cleared when the

Usage considerations: SessionStorage is suitable for temporary data needed during a single tab session, such as

Values
are
stored
as
strings;
to
store
objects
or
arrays,
you
must
serialize
with
JSON.stringify
and
parse
with
JSON.parse
when
retrieving.
For
example,
you
can
store
a
token
with
setItem('token',
'abc123')
and
later
read
it
with
getItem('token').
tab
is
closed.
It
is
confined
to
the
origin
and
is
not
accessible
by
pages
from
a
different
origin.
It
is
separate
from
localStorage,
which
persists
across
browser
sessions.
UI
state
or
non-sensitive
tokens
that
do
not
need
to
persist
after
the
tab
closes.
It
is
not
intended
for
long-term
storage
or
cross-tab
communication.
Be
mindful
that
storage
quotas
vary
by
browser
and
that
data
should
be
treated
as
untrusted
client-side
data.