Unused Expression Statement

ID

javascript.no_unused_expressions

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

JavaScript

Tags

dead-code, reliability

Description

Reports expression statements whose expression has no side effect — a bare identifier, a literal, an arithmetic / comparison expression standing alone. Such statements compute a value and immediately discard it, so they almost always indicate a dropped return, a leftover debugging line, or missing parentheses on a function call.

Rationale

  • x; looks similar to x() at a glance — the rule catches the missing parentheses.

  • a === b; looks similar to if (a === b) …​ with a missing if — the rule catches the dropped guard.

  • 42; is dead code; the literal contributes nothing.

The "use strict" family of directive prologues (string-literal expression statements at the start of a function body or module) is intentionally allowed.

// Bad - computed and discarded
x;
1 + 2;
a === b;

Remediation

Either remove the line, add the missing call site (e.g. x()), or wrap the expression in a real statement.

// Good
x();
const result = a === b;