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';

API Parameters

Example:

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