Log date · Wed
Can javascript-obfuscator change code behavior?
Obfuscated output can behave differently. We compare 5.6.0 and 5.8.1 on default objects and short-circuit evaluation.
Can obfuscation change JavaScript behavior?
Yes. With the same options on our sample, javascript-obfuscator 5.6.0 returned 1, 2 on successive calls using a default object; 5.8.1 and the original both returned 1, 1. Both versions skipped the right-hand call in our three short-circuit cases.
Released at 09:16 UTC on 2026-09-30, 5.8.1 fixed shared default-parameter objects (#1455) and control-flow flattening breaking short-circuit evaluation of &&, || and ?? (#1456). [1] Version 5.8.0 appeared on 2026-09-20, ten days earlier. [2] The notes do not identify the first affected version.
| Question | Result |
|---|---|
| Default object | 5.6.0: 1, 2; 5.8.1 and source: 1, 1 |
| Calls on short circuit | Zero in both versions |
| Null fallback | One call in both, returning side |
Sample, options and scope
We ran our own sample on Node.js 20.19.5 and transformed it with the Node API of versions 5.6.0 and 5.8.1. We set seed to 42, enabled transformObjectKeys and controlFlowFlattening, and set the threshold to 1; other options used their defaults. This covers one sample and seed, not every build or a complete application.
function fresh(options = { count: 0 }) {
options.count += 1;
return options.count;
}
let calls = 0;
function side() { calls++; return 'side'; }
console.log('defaults:', fresh(), fresh());
console.log('and:', false && side());
console.log('or:', true || side());
console.log('nullish:', 0 ?? side());
console.log('calls:', calls);
console.log('fallback:', null ?? side());
console.log('calls after fallback:', calls);The 5.8.1 documentation describes transformObjectKeys as an object-key transformation; the flattening threshold controls the probability of selecting a node, and a seed helps make results repeatable. [3] Fixing a seed makes this comparison easier to revisit, but a test campaign should not rely on one seed alone.
Default parameters and short circuits: the output
The default object should be created afresh for each call without an argument. The sample increments count, so both calls should return 1. The complete behavioral output from our run follows; the second value under 5.6.0 exposes state leaking between calls.
== javascript-obfuscator 5.6.0 ==
package: 5.6.0
options: {"seed":42,"controlFlowFlattening":true,"controlFlowFlatteningThreshold":1,"transformObjectKeys":true}
defaults: 1 2
and: false
or: true
nullish: 0
calls: 0
fallback: side
calls after fallback: 1== javascript-obfuscator 5.8.1 ==
package: 5.8.1
options: {"seed":42,"controlFlowFlattening":true,"controlFlowFlatteningThreshold":1,"transformObjectKeys":true}
defaults: 1 1
and: false
or: true
nullish: 0
calls: 0
fallback: side
calls after fallback: 1false &&, true || and 0 ?? should all skip side, while null ?? should call it once. Both versions behaved as expected on these specific branches, so this run did not reproduce the short-circuit defect. The stated scope of the fix comes from the project’s release notes, not an inference from these few lines. [1]
Recommendations by case
These are engineering recommendations, not benefits measured by the experiment. Treat obfuscation as a build step that affects the release artifact: compare side effects and exceptions as well as return values.
| Question | Result |
|---|---|
| Relevant options enabled | Upgrade to 5.8.1 and review errors in shipped releases. |
| Short-circuit guards | Cover truthy and falsy values, null, undefined and side effects on the right. |
| Mutable default object | Call repeatedly in one process and assert independent state. |
| Upgrade or option change | Pin the version, rerun integration tests on the final artifact and retain a rollback build. |
Real failures may depend on inputs, call order or runtime environment. Include important user flows, error handling and cross-module interfaces in the regression suite. For a browser or Electron application, also test in the target runtime instead of relying on Node alone. Record the build version, options and seed alongside results so a difference can be investigated.
Before release, record a baseline in a test environment: return values, exception types and the number of external calls for the same inputs. When a comparison fails, first check that the two artifacts use the same dependencies and runtime, then change the version or options one at a time. This helps distinguish a business logic change from a configuration or transformation problem. Use synthetic data for regression cases involving user information and restrict access to the resulting logs. A passing small test is a starting point for a wider release suite, not a substitute for it.
Test your own application
In a project with 5.8.1 installed and pinned, generate an artifact from your own test entry and compare behavior in the same runtime. The commands below are a starting point; replace the paths and use your actual configuration in the release pipeline.
node path/to/your-test-entry.js > /tmp/source-result.txt
pnpm exec javascript-obfuscator path/to/your-test-entry.js --output /tmp/obfuscated-test.js --seed 42 --control-flow-flattening true --control-flow-flattening-threshold 1 --transform-object-keys true
node /tmp/obfuscated-test.js > /tmp/obfuscated-result.txt
diff -u /tmp/source-result.txt /tmp/obfuscated-result.txtOutput comparison does not replace assertions: check exit status, thrown errors, network and storage side effects, and state after repeated calls. Run end-to-end tests on the final packaged artifact, and repeat them after upgrades, option changes or build-order changes. Retain the corresponding unobfuscated build and controlled diagnostic materials to investigate release-only failures.
Your checklist
- Pin the obfuscator version and release configuration.
- Review errors in older releases using the affected options.
- Assert that default objects stay independent across calls.
- Cover short-circuit return values and side effects.
- Test the final release artifact in its target runtime.
Primary sources
- GitHub: javascript-obfuscator release 5.8.1 · Source date 2026-09-30 · Checked 2026-11-11
- GitHub: javascript-obfuscator release 5.8.0 · Source date 2026-09-20 · Checked 2026-11-11
- javascript-obfuscator 5.8.1 README · Checked 2026-11-11