Web Storage (localStorage, sessionStorage, cookies)

What storage management practice is demonstrated in this code?
// Before storing large data
const calculateStorageUsage = () => {
  let total = 0;
  for (let i = 0; i < localStorage.length; i++) {
    const key = localStorage.key(i);
    const value = localStorage.getItem(key);
    total += key.length + value.length;
  }
  return total;
};

const storageLimit = 5 * 1024 * 1024; // 5MB
const currentUsage = calculateStorageUsage();
const newDataSize = JSON.stringify(newData).length;

if (currentUsage + newDataSize > storageLimit) {
  // Implement storage cleanup or compression
}
Next Question (14/20)