JavaScript

JavaScript

Made by DeepSource

Found unreachable code JS-0025

Performance
Major

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.

Bad Practice

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");

Recommended

function func() {
    return calc();
    function calc() {
        return 1;
    }
}

switch (func) {
    case 1:
        var x = get_x();
        use_x(x);
        break;
}