loading...
re: Is there a way to modify getAnimals() to change the default answer?
 

Edit, I misread the question. Here is the corrected response.

Sure. As @Alain mentioned, you can use an optional parameter.

Optional Parameter

const loadAnimals = () => {  
  animals = {
    dog: "LOVELY",
    cat: "CUTE",
    pony: "AWESOME",
  };
};

const getAnimals = (overrides = {}) => {
  if(!animals) loadAnimals();
  return {
    ...animals,
    ...overrides,
  };
};

getAnimals({
  dog: "GREAT",
  monkey: "AGILE",
}); // -> {dog: "GREAT", cat: "CUTE", pony: "AWESOME", monkey: "AGILE"}

Thanks for your comment.

code of conduct - report abuse