NOOP (Null operator)

A function that performs no operations and once invoked it returns »undefined«. Thus »noop« simply means »no operation«.

Basically, such a function be implemented as follows.

const noop = () => {};

It can be useful when needing a fallback value/function in case e.g. a callback function wasn’t passed.

const doSomething = (callback) => {
  const result = calculateResult();
  (callback || noop)(result);
}

As some linters disallow empty function bodies, it’s best practice to simply put the comment /* NOOP */ in the empty function body.

const noop = () => { /* NOOP */ };