Skip to content

noop

noop is a simple function that does nothing. It returns undefined and accepts no arguments. Useful as a default callback or placeholder.

Best for defaults and placeholders Use noop when you need a function that does nothing, such as a default callback value.

Root package:

import { noop } from "@vgerbot/async";

Module subpath:

import { noop } from "@vgerbot/async/utils";

Leaf subpath:

import { noop } from "@vgerbot/async/utils/noop";
import { noop } from "@vgerbot/async";
const fn = condition ? realCallback : noop;
fn(); // Does nothing if condition was false
  • Default callbacks: Provide a no-op default for optional callback parameters.
  • Placeholder functions: Use as a placeholder before the real function is assigned.
  • Testing: Use as a mock or stub that does nothing.
  • Conditional execution: Avoid if checks by using noop as the fallback.
function noop(): void;

Returns undefined.

function fetchData(onSuccess: () => void = noop) {
// ...
onSuccess();
}
const log = debugMode ? console.log : noop;
log("This only logs in debug mode");
  • constant — returns a constant value as a CancellableHandle.
  • asyncify — wraps sync functions.
  • once — executes a function only once.