Testing

const: Browser Support, Block Scope, Limitations

JavaScript const works in Chrome 49+, Edge 12+, Firefox 36+, Safari 11+, Opera 36+, and Samsung Internet 5+, with partial support in Internet Explorer 11.

Author

Prince Dewani

May 6, 2026

const is an ECMAScript 2015 (ES6) statement that declares a block-scoped variable whose binding cannot be reassigned after initialization. It works in Chrome 49+, Edge 12+, Firefox 36+, Safari 11+, Opera 36+, and Samsung Internet 5+, with partial support in Internet Explorer 11 and no support in Internet Explorer 6 to 10.

This guide covers what const is, the browsers that support it, the key features, the difference between const, let, and var, how to use const in older browsers, and the known limitations.

What is const?

const is an ECMAScript 2015 declaration statement that creates a block-scoped, read-only binding tied to a value. The engine resolves the binding inside the nearest enclosing block, and it throws a TypeError on any attempt to reassign the variable after the line that declared it.

Which browsers does const support?

Every modern desktop and mobile browser supports const by default, while Internet Explorer 11 ships only partial support and earlier Internet Explorer builds do not parse it at all.

Loading browser compatibility data...

const compatibility in Chrome

Chrome supports const by default from Chrome 49 on Windows, macOS, Linux, ChromeOS, and Android. Chrome 21 to 48 had partial support that allowed the keyword but skipped block scope and proper temporal dead zone behavior. Chrome 4 to 20 did not support const at all.

const compatibility in Edge

Microsoft Edge supports const fully from Edge 12 across Windows, macOS, Linux, Android, and iOS. The Chromium-based Edge 79 and later inherits Chrome's V8 implementation, so block scope, temporal dead zone, and reassignment errors all match Chrome behavior on every Edge release in support.

const compatibility in Firefox

Firefox supports const fully from Firefox 36 on Windows, macOS, Linux, and Android. Firefox 4 to 35 shipped a non-standard, function-scoped const that predates the ES6 spec and behaves more like var with reassignment guarded. Treat anything below Firefox 36 as partial support and transpile when you target it.

const compatibility in Safari

Safari supports const fully from Safari 11 on macOS High Sierra, and from Safari 11 on iOS 11 and iPadOS 11. Safari 5.1 to 10 had partial support with spec gaps in block scope inside catch clauses and module-level redeclaration. Safari 5 and earlier do not support const.

const compatibility in Opera

Opera supports const fully from Opera 36 on Windows, macOS, Linux, and Android. Opera 12 to 35 had partial support that mirrored the early Chromium implementation. Opera Mini does not run a full JavaScript engine on the device, so its server-side rendering path skips most const-dependent code paths.

const compatibility in Samsung Internet

Samsung Internet supports const fully from Samsung Internet 5 on Galaxy phones and tablets. Samsung Internet 4 had partial support that tracked the early Chromium build it shipped on top of. The current Samsung Internet engine inherits V8 from Chromium, so const behavior matches Chrome for Android.

const compatibility in Android Browser

Chrome for Android supports const fully on every release in active support, matching desktop Chrome 49 and later. The legacy stock Android Browser used on Android 4.3 and earlier had partial support, with the same block-scope gaps as early Chromium. Modern Android devices ship Chrome, Samsung Internet, or Firefox, all with full support.

const compatibility in Internet Explorer

Internet Explorer 11 has partial support for const, with several gaps: missing block scope inside catch clauses, inconsistent redeclaration errors, and no temporal dead zone enforcement. Internet Explorer 6 to 10 do not support const at all. Microsoft has retired Internet Explorer, so any site that still targets it should transpile const to var.

Note

Note: const behaves slightly differently across older Safari, Firefox, and Internet Explorer engines. Test it on real browsers and OS with TestMu AI. Try TestMu AI free!

What are the key features of const?

const gives JavaScript four guarantees that var never offered, all enforced at parse time or at the line that runs the declaration.

  • Block scope: A const binding lives only inside the nearest pair of curly braces, so a const declared inside an if, for, or arrow body is invisible outside it. This stops the loop-variable leakage that var produced.
  • No reassignment: Any attempt to assign a new value to a const after initialization throws a TypeError at runtime. The check is a real engine guard, not a lint rule, so refactors cannot silently break it.
  • Mandatory initializer: A const must bind a value on the same statement that declares it. const x; without an initializer is a SyntaxError caught before the script runs.
  • Temporal dead zone: The binding exists from the top of its block but cannot be read until the declaration line runs. Touching it earlier throws a ReferenceError, which surfaces ordering bugs that var hid behind undefined.
  • No silent redeclaration: Declaring the same const twice in one block is a SyntaxError. var allowed silent re-declarations that buried bugs in long files; const fails fast at parse time.

What is the difference between const, let, and var?

All three declare variables, but only const and let follow modern block-scope rules. The table below shows the practical differences a QA engineer or developer needs when picking one.

Behaviorconstletvar
ScopeBlockBlockFunction
Reassignment allowedNo, throws TypeErrorYesYes
Initializer requiredYes, SyntaxError without itNoNo
Temporal dead zoneYesYesNo, hoists as undefined
Redeclaration in same scopeSyntaxErrorSyntaxErrorAllowed silently
Object or array contentsMutableMutableMutable
Internet Explorer 11PartialPartialFull
...

How do you use const in older browsers?

Older Internet Explorer, early Safari, and pre-36 Firefox builds need a transpilation step that rewrites const to var while preserving the scope rules. The standard tool is Babel with @babel/preset-env, configured against your browserslist target.

  • Install Babel: Run npm install --save-dev @babel/core @babel/cli @babel/preset-env so the toolchain is available locally.
  • Add a browserslist target: Drop a browserslist field into package.json that names the older browsers you ship to, for example "ie 11" and "safari >= 9".
  • Configure preset-env: Create a babel.config.json with the preset entry ["@babel/preset-env", { "targets": { "esmodules": false } }] so Babel reads the browserslist field and rewrites const where needed.
  • Run the build: Pipe your source through npx babel src --out-dir dist, then point your bundler or static host at the dist folder.
  • Confirm the output: Open the compiled JavaScript and search for const. On a correct Internet Explorer 11 target, every const should be rewritten to var with a unique name per block.
  • Detect support at runtime: Paste the snippet below into the target browser's DevTools console to confirm whether the engine handles const or whether the transpiled bundle is required.
// Run in any browser DevTools console to confirm const support and block scope.
try {
  new Function("const sample = 1; { const sample = 2; } if (sample !== 1) throw new Error('block-scope-broken');")();
  console.log("const declaration: supported");
  console.log("Block scope: working");
} catch (error) {
  console.warn("const not fully supported:", error.message);
}

try {
  new Function("const value = 1; value = 2;")();
  console.warn("Reassignment did not throw - const enforcement is broken.");
} catch (error) {
  console.log("Reassignment guard: working (" + error.name + ")");
}

If the snippet logs a warning, the browser does not enforce const. Ship the transpiled bundle for that user agent and keep the original const-based bundle for modern browsers.

...

What are the limitations of const?

const locks the binding, not the value. That gap, plus a handful of older-browser quirks, is the source of every const-related bug worth knowing.

  • Object and array contents stay mutable: A const bound to an object lets you push into arrays, set new keys, and reassign properties. Use Object.freeze on the value when callers must not mutate the contents.
  • Internet Explorer 11 partial support: IE 11 parses const but skips block scope inside catch clauses and never throws on redeclaration. Code that runs in IE 11 needs a Babel transpile, not a polyfill.
  • No polyfill exists: const is a parser-level keyword, not an API call, so a runtime polyfill cannot patch it. The only fix for older engines is a transpiler that rewrites const into var with the right scope guards.
  • Temporal dead zone surprises: Reading a const before its declaration line throws a ReferenceError, even when a same-name var or function is in scope. This breaks code that moved between var-style and const-style files without a careful audit.
  • Loop bindings need care: A const inside for (const i = 0; ... ) {} cannot increment, so the loop runs once or fails. Use let for the iteration variable and const for the per-iteration values destructured from it.
  • No global property created: A top-level const at the script level does not become a property on window or globalThis, unlike a top-level var. Browser extensions and ad scripts that probe window for globals will not see const-bound names.

In my experience, the most common failure is a developer assuming const freezes an object and then watching a teammate mutate the contents in another file. Pair const with Object.freeze, or hand the value out through a getter that returns a defensive copy, when the team needs the value itself to stay constant.

Citations

All const version numbers and platform notes in this guide come from these primary sources:

Author

Prince Dewani is a Community Contributor at TestMu AI, where he manages content strategies around software testing, QA, and test automation. He is certified in Selenium, Cypress, Playwright, Appium, Automation Testing, and KaneAI. Prince has also presented academic research at the international conference PBCON-01. He further specializes in on-page SEO, bridging marketing with core testing technologies. On LinkedIn, he is followed by 4,300+ QA engineers, developers, DevOps experts, tech leaders, and AI-focused practitioners in the global testing community.

Open in ChatGPT Icon

Open in ChatGPT

Open in Claude Icon

Open in Claude

Open in Perplexity Icon

Open in Perplexity

Open in Grok Icon

Open in Grok

Open in Gemini AI Icon

Open in Gemini AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free

Frequently asked questions

Did you find this page helpful?

More Related Hubs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests