In JavaScript, any code following a return, throw, continue, or break statement is unreachable and will never be executed. The only exception here is declarations, which are valid because of JavaScript Hoisting.
Non-Compliant Code Examples
functionfn(){x=1;returnx;x=3;// this will never execute
}classCextendsB{#x;// this will never be added to instances
constructor(){return{};}}functionfoo(){returntrue;console.log("done");}functionbar(){thrownewError("Oops!");console.log("done");}functionloop(){while(value){break;console.log("done");}}functionerror(){thrownewError("Oops!");console.log("done");}functionbaz(){if(Math.random()<0.5){return;}else{thrownewError();}console.log("done");}functionanotherLoop(){for(;;){}console.log("done");}switch(foo){case1:break;x=2;}classCextendsB{#x;// unreachable
#y=1;// unreachable
a;// unreachable
b=1;// unreachable
constructor(){return{};}}