Exercise 8: Storage Size Calculator

Problem Statement

Function `getStorageSize()` banao jo localStorage ka total size calculate kare in bytes. Example: getStorageSize() => 1024 (bytes)

Sample Output:

getStorageSize() => 1024 (bytes)
// Returns total storage size

Solution

const getStorageSize = () => {
  let total = 0;
  for (let key in localStorage) {
    if (localStorage.hasOwnProperty(key)) {
      total += localStorage[key].length + key.length;
    }
  }
  return total;
};

Explanation

Overall Goal:

  • LocalStorage ka total size calculate karna.

Real world:

  • Storage monitoring: size tracking.
  • Quota management: storage limits.