Why is this an issue?

The void operator evaluates its argument and always returns undefined. void operator allows using any expression in the places where an undefined is expected. However, using void makes code more difficult to understand, as the intent is often not clear.

void doSomething();  // Noncomplaint

In ECMAScript5 and newer environments, the global property undefined cannot be reassigned, so using void for this reason should also be avoided.

undefined = 'Hello, world!'; // since ECMAScript5, this statement has no effect
if (parameter === void 42) { // Noncompliant
   // ...
}

Exceptions

if (parameter === void 0) { // Compliant
   // ...
}
void function() { // Compliant
   // ...
}();
const promise = new Promise((resolve, reject) => resolve(42));
void promise;

How to fix it

When using void …​ to get the undefined value, directly use the undefined identifier instead.

Code examples

Noncompliant code example

if (parameter === void 42) { // Noncompliant
   // ...
}

Compliant solution

if (parameter === undefined) {
   // ...
}

Otherwise, the void operator should be removed to avoid confusion for maintainers.

Noncompliant code example

doSomethingElse(void doSomething()); // Noncompliant

Compliant solution

doSomething();
doSomethingElse();

Resources

Documentation