All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S3699.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy