In JavaScript, we can express a simple noop function like so (It's the same in Lodash):
const noop = () => {};
It might be a frivolous distinction, but does it count as a pure function? My initial guess was that it is because:
- Referentially transparent because it always returns
undefined
. - Doesn't cause any side effect.
But if we invoke this function repeatedly (like the code block below that assigns undefined
to a bunch of variables), wouldn't it eventually cause a different behavior (like crashing the program) because the external state has been changing all along?
const a = noop();
const b = noop();
const c = noop();
const d = noop();
...
...
(... until memory runs out)
(Or should we just leave aside the question of memory, etc. in this context?)