Constant Folding

Potency Low
Resilience High
Cost None
Tags: optimization, constant, folding, minification, compiler

Description

Constant folding is a compiler optimization. The transformation evaluates constant expressions at compile-time to reduce them to the minimum equivalent expression reducing the computing effort in run-time.

Code Annotation Example

// @jscrambler enable constantFolding

Example

The following example shows an expression that evaluate to a constant value:

1 + 2 + '' + 3;

Because this always produce the same output, we can replace the expression with its constant value.

'33';

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": "constantFolding"
    }
  ]
}