This rule raises an issue when a function call result is used, even though the function does not return anything.

Why is this an issue?

When a function in JavaScript does not have a return statement or if it has a return statement without a value, it implicitly returns undefined. This means that a function without a return statement or with an empty return statement is, in a way, a "void" function, as it doesn’t return any specific value.

Therefore, attempting to use the return value of a void function in JavaScript is meaningless, and it can lead to unexpected behavior or errors.

Code examples

Noncompliant code example

function foo() {
  console.log("Hello, World!");
}

let a = foo(); // Noncompliant: Assigning the return value of a void function

You should not use in any way the return value of a void function.

Compliant solution

function foo() {
  console.log("Hello, World!");
}

foo();

Resources

Documentation