Some code paths are unreachable because the return
, throw
, break
, and continue
statements unconditionally exit a block of code.
The code statements after the above keywords (which exit the code block) will not execute.
function func() {
return true;
next_func();
}
function add(a, b) {
throw new Error("Oops!");
return a + b;
}
while(value) {
break;
do_action();
}
throw new Error("Oops!");
console.log("done");
function check() {
if (Math.random() < 0.5) {
return;
} else {
throw new Error();
}
console.log("done");
}
for (;;) {}
console.log("done");
function func() {
return calc();
function calc() {
return 1;
}
}
switch (func) {
case 1:
var x = get_x();
use_x(x);
break;
}