Skip to main content

JavaScript Question 78

Question 78 of 0JavaScript

What is the output?

Login Required

Please login to select answers and solve this question. You can view the question without logging in.

Code:
const add = () => {
  const cache = {};
  return num => {
    if (num in cache) {
      return `From cache! ${cache[num]}`;
    } else {
      const result = num + 10;
      cache[num] = result;
      return `Calculated! ${result}`;
    }
  };
};

const addFunction = add();
console.log(addFunction(10));
console.log(addFunction(10));
console.log(addFunction(5 * 2));

Select the correct option: