Complete the code to store a value in the cache object.
cache['user'] = [1];
We assign the string 'John' to the cache key 'user' to store the value.
Complete the code to check if the cache has a stored value for 'user'.
if (cache.hasOwnProperty([1])) { console.log('Cache hit'); }
We check if the cache has the key 'user' to know if the data is cached.
Fix the error in the code to retrieve cached data safely.
const userData = cache[1];Accessing cache with square brackets and the key string retrieves the cached value.
Fill both blanks to create a cache check and fallback fetch.
const data = cache[1] [2] fetchFromDB();
We access cache['item'] and use || to fetch from DB if cache is empty or falsey.
Fill all three blanks to implement a simple cache update after fetching data.
if (!cache[1]) { cache[2] = fetchData(); } return cache[3];
We check if cache['key'] is missing, then store fetched data in cache['key'], and finally return cache['key'].
