---
url: /reference/OutputOptions.topLevelVar.md
---
# topLevelVar

* **Type**: `boolean`
* **Optional**

Whether to convert top-level `let` and `const` declarations into `var` declarations.

Enabling this option can improve runtime performance of the generated code in
certain environments by avoiding Temporal Dead Zone (TDZ) checks. Only declarations
in the module's top-level scope are rewritten — declarations inside nested scopes
(functions, blocks, etc.) are left as-is.

Note:

* Top-level `class X {}` declarations are always emitted as `var X = class {}` so
  rolldown can hoist them alongside other top-level bindings; this transform is
  independent of `topLevelVar`.
* Top-level `function` declarations are never rewritten.

## Default

false

## In-depth

Multiple JavaScript engines have had and continue to have performance issues with [Temporal dead zone (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz) checks. These checks validate that a let, const, or class symbol isn't used before it's initialized.

Related issues:

* V8: https://issues.chromium.org/issues/42203665
* JavaScriptCore: https://bugs.webkit.org/show\_bug.cgi?id=199866 (fixed)
