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
noopwhen you need a function that does nothing, such as a default callback value.
Import
Section titled “Import”Root package:
import { noop } from "@vgerbot/async";Module subpath:
import { noop } from "@vgerbot/async/utils";Leaf subpath:
import { noop } from "@vgerbot/async/utils/noop";Quick example
Section titled “Quick example”import { noop } from "@vgerbot/async";
const fn = condition ? realCallback : noop;fn(); // Does nothing if condition was falseWhen to use noop
Section titled “When to use noop”- 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
ifchecks by usingnoopas the fallback.
function noop(): void;Return value
Section titled “Return value”Returns undefined.
Usage patterns
Section titled “Usage patterns”Default callback
Section titled “Default callback”function fetchData(onSuccess: () => void = noop) { // ... onSuccess();}Conditional function
Section titled “Conditional function”const log = debugMode ? console.log : noop;log("This only logs in debug mode");