Kunal Bhalla
Sep 7, 2018 · 1 min read

For the cache case, I’ve ended up settling on a third variant so that there’s exactly one return which feels a little bit more natural to me because there’s a single exit point for the function.

cache = … look up cached value …

if (!cache) {

… compute cached value (I generally extract that to a second function) …

… store appropriately, and set cache to the newly computed value …
}

return cache;

    Kunal Bhalla

    Written by

    Indifferent and inconsistent Tweeter.