Unreachable code is the code whose statements cannot be executed under any circumstances. Jump statements, like return
,
break
, continue
, and throw
, alter the normal flow of control within a program, making it possible to skip
certain parts of the code, terminate loops prematurely, or exit from functions. So any statements that come after a jump are effectively
unreachable.
Unreachable statements can be a sign of a logical error or oversight in the program’s design, leading to unexpected behavior at runtime.
function func(a) {
let i = 10;
return i + a;
i++; // Noncompliant: this is never executed
}
Identify and remove unreachable statements from your code.
function func(a) {
let i = 10;
return i + a;
}