Skip to content

voidOperator

Reports using the void operator.

✅ This rule is included in the ts stylistic preset.

The void operator evaluates an expression and returns undefined, regardless of the expression’s value. While this was historically used to safely obtain undefined, modern JavaScript has undefined as a proper value, making the void operator unnecessary and potentially confusing. void 0 is specifically used in minified code to lower total character size, but that is not necessary in source code. Using undefined directly is clearer and more explicit.

const value = void 0;
function process() {
void doSomething();
}
const callback = () => void action();

This rule is not configurable.

If you have a specific code style that requires the use of void operator, you might want to disable this rule. However, in most modern codebases, using undefined directly is preferred for clarity.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.