Storage

sessionStorage.clear

Removes all key/value pairs from the sessionStorage object for the current session

Syntax

JavaScript
sessionStorage.clear()

Return Value

undefined

Examples

Basic Usage
sessionStorage.clear()
console.log(sessionStorage.length) // 0
Practical Example
function resetWizard() {
  sessionStorage.clear()
  window.location.href = '/wizard/step-1'
}
Advanced Usage
const count = sessionStorage.length
sessionStorage.clear()
console.log(`Cleared ${count} session items`)

Understanding sessionStorage.clear

The sessionStorage.clear method in JavaScript removes all key/value pairs from the sessionStorage object for the current session. It belongs to the Storage object and is one of the most widely used methods for working with storage values in modern JavaScript and TypeScript applications.

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

Common use cases for sessionStorage.clear include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like sessionstorage-removeitem, localstorage-clear, sessionstorage-setitem, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for sessionStorage.clear 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 Storage Methods

Other methods in the Storage object

Related Tools

More Storage Methods

Explore JavaScript Methods

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