Call or return
JavaScript, Function · Apr 4, 2022

Calls the argument if it's a function, otherwise returns it.
const callOrReturn = (fn, ...args) =>
typeof fn === 'function' ? fn(...args) : fn;
callOrReturn(x => x + 1, 1); // 2
callOrReturn(1, 1); // 1