1 # disallow unreachable code after `return`, `throw`, `continue`, and `break` statements (no-unreachable)
3 Because the `return`, `throw`, `break`, and `continue` statements unconditionally exit a block of code, any statements after them cannot be executed. Unreachable statements are usually a mistake.
9 x = 3; // this will never execute
13 Another kind of mistake is defining instance fields in a subclass whose constructor doesn't call `super()`. Instance fields of a subclass are only added to the instance after `super()`. If there are no `super()` calls, their definitions are never applied and therefore are unreachable code.
17 #x; // this will never be added to instances
27 This rule disallows unreachable code after `return`, `throw`, `continue`, and `break` statements. This rule also flags definitions of instance fields in subclasses whose constructors don't have `super()` calls.
29 Examples of **incorrect** code for this rule:
32 /*eslint no-unreachable: "error"*/
40 throw new Error("Oops!");
49 throw new Error("Oops!");
53 if (Math.random() < 0.5) {
65 Examples of **correct** code for this rule, because of JavaScript function and variable hoisting:
68 /*eslint no-unreachable: "error"*/
89 Examples of additional **incorrect** code for this rule:
92 /*eslint no-unreachable: "error"*/
96 #y = 1; // unreachable
106 Examples of additional **correct** code for this rule:
109 /*eslint no-unreachable: "error"*/
128 // implicit constructor always calls `super()`