CodeQL documentation

Unreachable statement

ID: js/unreachable-statement Kind: problem Security severity: Severity: warning Precision: very-high Tags: - quality - reliability - correctness - external/cwe/cwe-561 Query suites: - javascript-code-quality.qls - javascript-security-and-quality.qls 

Click to see the query in the CodeQL repository

An unreachable statement almost always indicates missing code or a latent bug and should be examined carefully.

Recommendation

Examine the surrounding code to determine why the statement has become unreachable. If it is no longer needed, remove the statement.

Example

In the following example, a spurious semicolon after the if condition at line 2 makes the return statement on line 4 unreachable: the function will always execute the return statement on line 3 first, so it will never reach line 4.

function f() { if (someCond()); return 23; return 42; } 

To correct this issue, remove the spurious semicolon:

function f() { if (someCond()) return 23; return 42; } 

References