JavaScript

JavaScript

Made by DeepSource

Found unused expressions JS-0093

Bug risk
Minor
Autofix

An unused expression that does not affect the state of the program indicates a logic error.

For example, if a programmer wants to increment the value of a variable a by one, and intends to do so through this code:

let a = 0
a = a + 1
console.log(a) // output 1

But because of a typo, writes the following:

let a = 0
a + 1
console.log(a)

Here, the expression a + 1 does nothing meaningful in the program's runtime. The expression is thus considered "unused" and should be removed.

Bad Practice

0

if(0) 0

{0}

f(0), {}

a, b()

c = a, b;

a() && function namedFunctionInExpressionContext () {f();}

(function anIncompleteIIFE () {});

injectGlobal`body{ color: red; }`

Recommended

{} // In this context, this is a block statement, not an object literal

{myLabel: someVar} // In this context, this is a block statement with a label and expression, not an object literal

function namedFunctionDeclaration () {}

(function aGenuineIIFE () {}());

f()

a = 0

new C

delete a.b

void a