SessionStorage.clear JavaScript Example

SessionStorage.clear() : clears all keys stored in a given SessionStorage object.

This method, when invoked clears the entire storage of all records for that domain. It does not receive any parameters.


// Save data to sessionStorage
sessionStorage.setItem('key', 'value');

// Get saved data from sessionStorage
let data = sessionStorage.getItem('key');

// Remove saved data from sessionStorage

// Remove all saved data from sessionStorage

localStorage.clear() Method Example

The following function creates three data entries in local storage and then deletes them by using clear().
function populateStorage() {
  sessionStorage.setItem('bgcolor', 'red');
  sessionStorage.setItem('font', 'Helvetica');
  sessionStorage.setItem('image', 'miGato.png');



Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course