Is there a way to modify getAnimals() to change the default answer?
It could be passed as a(n optional) second parameter.
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.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Is there a way to modify getAnimals() to change the default answer?
It could be passed as a(n optional) second parameter.
Edit, I misread the question. Here is the corrected response.
Sure. As @Alain mentioned, you can use an optional parameter.
Optional Parameter
Thanks for your comment.