49 lines
849 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
Jump statements (``++return++``, ``++break++`` and ``++continue++``) and ``++throw++`` expressions move control flow out of the current code block. So any statements that come after a jump are dead code.
2020-06-30 12:47:33 +02:00
== Noncompliant Code Example
----
function fun(a) {
var i = 10;
return i + a;
i++; // Noncompliant; this is never executed
}
----
== Compliant Solution
----
function fun(int a) {
var i = 10;
return i + a;
}
----
== Exceptions
2021-01-27 13:42:22 +01:00
This rule ignores unreachable ``++break++`` statements in ``++switch++`` clauses.
2020-06-30 12:47:33 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:47:33 +02:00
----
switch (x) {
case 42:
return 43;
break; // Compliant
default:
doSomething();
}
----
Hoisted variables declarations without initialization are always considered reachable.
2020-06-30 12:47:33 +02:00
----
function bar() {
return x = function() {
x.foo = 42;
}
var x;
}
----
include::../see.adoc[]