Dead Code Elimination

Potency None
Resilience High
Cost None
Tags: dead, optimization, removal, elimination

Description

Dead code is code that is never executed. Dead Code Elimination removes dead code from your program resulting in a smaller program that behaves exactly the same.

Code Annotation Example

// @jscrambler enable deadCodeElimination

Example

The following example contains dead code:

while (true) {
  if (key === 'up') {
    shoot();
  } else if (false) {
    // this is unreachable code
    deleteShip();
  } else {
    key = 'exit'
    break;
    // this is also unreachable code
    key = 'down';
  }
}

The resulting code looks like this:

while (true) {
  if (key === 'up') {
    shoot();
  } else {
    key = 'exit';
    break;
  }
}

Browser Compatibility

Browser Compatible Versions Tested Versions Notes
Chrome 80+ 80+
Firefox 90+ 90+
Internet Explorer 8+ 8+
Microsoft Edge 116+ 116+
Safari 13.1+ 13.1+

API Parameters

Example:

{
  "keys": {
    "accessKey": "XXXXXX",
    "secretKey": "YYYYYY"
  },
  "applicationId": "ZZZZZZ",
  "params": [
    {
      "name": "deadCodeElimination"
    }
  ]
}