How to use the ES6 to ES5 converter
- Paste your code into the JavaScript box.
- Pick the Quotes style, Double or Single, for strings the tool creates from template literals.
- Copy the ES5 code or download
script.es5.js. - Read the Converted table to see what changed, and any warning that starts “Not converted” to see what still needs work.
What it does and when to use it
Some places still run only ES5: old smart TVs and set-top boxes, embedded web views, legacy intranet browsers and a few scripting hosts. When you need one small function to run there, a full build setup is overkill. This tool rewrites the syntax with fixed rules and tells you honestly what it skipped.
Check the input first with the JavaScript validator, since the converter needs code that parses. To handle only template literals, the template literal to concat converter is lighter, and var to let / const goes the opposite way. Tidy the output with the JavaScript formatter.
How it works
The code is parsed with the Babel parser into a syntax tree. The tool then regenerates only the nodes it converts and copies everything else from your source, so comments and layout outside those spots stay as they were.
| ES2015+ | ES5 output |
|---|---|
x => x * 2 |
function (x) { return x * 2; } |
arrow using this |
(function () { … }).bind(this) |
let / const |
var |
`a${b}c` |
"a" + b + "c" |
function f(b = 2) |
function f(b) { if (b === void 0) { b = 2; } … } |
(...nums) => |
var nums = Array.prototype.slice.call(arguments, 0); |
{ x, m() {} } |
{ x: x, m: function () {} } |
Worked examples
Default parameter and template literal.
const greet = (name = 'friend') => `Hello, ${name}!`;
becomes:
var greet = function (name) { if (name === void 0) { name = 'friend'; } return "Hello, " + name + "!"; };
Syntax it will not convert.
class Cart { add(...items) { return [...items]; } }
const { a, b } = obj;
const total = price ?? 0;
Only const changes. The warning lists class declarations, rest in destructuring and spread on line 1, object destructuring on line 2 and nullish coalescing on line 3. Line 2 comes out as var { a: a, b: b } = obj;, which is still not ES5, so fix flagged lines yourself.
A loop closure. for (let i = 0; i < 3; i++) { setTimeout(() => log(i)); } becomes for (var i = 0; i < 3; i++) { setTimeout(function () { return log(i); }); }. The tool warns because with var every callback sees the final i, so this logs 3 three times instead of 0, 1, 2. Wrap the body in a function that takes i as a parameter.
Limits and tips
- Arrows that use arguments get a warning, because
argumentsnow means the new function’s own arguments. - No polyfills and no module bundling. Remove
importandexportyourself or use a bundler. - Test the output in the target browser; syntax conversion cannot catch missing built-in methods.
Frequently asked questions
Is this a replacement for Babel?
Why does my class stay as it is?
Does it add polyfills for Promise, Array.from or fetch?
What does .bind(this) in the output mean?
Why does const become var?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.