Loading ES5 to ES6 Converter...
Please wait a moment

How to Convert ES5 to ES6+ - Step by Step Guide

Step 1

Input Your ES5 Code

Let's modernize your legacy ES5 code to ES6+! You have several options:

•
Paste directly: Copy your ES5 JavaScript and paste it into the input editor
•
Upload a file: Click "Upload" to select a .js file from your computer for modernization
•
Try the sample: Click "Sample" to see conversion examples

Example: ES5 Code Input

Here's legacy ES5 JavaScript:

var numbers = [1, 2, 3];
var doubled = numbers.map(function(n) {
  return n * 2;
});
Step 2

Automatic Modern Syntax Conversion

The code is converted as you type. Three changes are made, each only where it is safe:

•
Arrow functions: Anonymous function expressions such as callbacks become arrow functions, unless they use this or arguments or are called with new
•
Let and const: var becomes const, or let if it is reassigned; a var used before its line or inside a loop or block stays var
•
Template literals: Joins that start with text, like "Hi " + name, become template strings

Example: Modern ES6+ Output

The same code with modern syntax:

const numbers = [1, 2, 3];
const doubled = numbers.map((n) => {
  return n * 2;
});
Step 3

Review Modern Features

Check the modernized code with ES6+ features:

•
Cleaner syntax: More concise and readable code
•
Better scoping: Block-level scoping with let and const
•
What stayed: The note above the output counts the var and function lines that were left as written, so you know what to look at
Step 4

Export Modern Code

Save your modernized JavaScript:

•
Copy to clipboard: One-click copying for your project
•
Download as file: Save as a .js file with modern syntax
•
Ready to use: Compatible with modern browsers and Node.js

Frequently Asked Questions

What exactly does the converter change?

Three things. var becomes const when the variable is never reassigned, or let when it is. Anonymous function expressions such as callbacks become arrow functions. And string joins that start with a piece of text, like "Hello, " + name + "!", become template literals. It does not add destructuring, spread, default parameters or modules, and it does not turn constructor functions and prototype methods into classes. A note above the output lists what was changed and what was left alone.

Will the converted code behave the same way?

That is the whole point of the rules it follows. Your code is parsed first, and a change is only made where it can't alter the result: a var that is used before its line, declared twice, or sits inside a loop or an if block stays var, because let and const would change its scope or throw. A function that uses this or arguments, is called with new, or has a name stays a regular function, because arrows handle those differently. One small difference remains with template literals: an object with a custom valueOf() is turned into text with toString() instead. Run your tests on the result before shipping it.

Why did some var or function lines stay the same?

Because changing them could break the code. A typical case is for (var i = 0; ...) with callbacks inside the loop: with let, every callback would see its own i instead of the shared one. Another is a function that reads this, like an object method or a constructor; as an arrow it would read this from the surrounding code instead. Those lines are counted in the note above the output so you can review them yourself.

Does it reformat my code or touch my numbers and strings?

No. Only the var keyword, the function head and the string joins are rewritten; indentation, comments, quotes and every literal stay as you typed them. A long ID like 8901240544102066246, a zip code "00501" or a price 14.50 comes out with every character the same. Text inside strings, comments and regular expressions is never changed, even if it contains the word var or function.

What happens if my code has a syntax error?

You get the line and column of the problem with the line shown and a marker under the spot, and no output. Fix that line and the conversion runs again on its own.

Will ES6 code run in older browsers?

const, let, arrow functions and template literals work in every current browser and in Node.js, but not in Internet Explorer. If you still need to support it, compile the result back down with Babel or a similar build step.

Is my code uploaded anywhere?

No. Parsing and converting happen in your browser, and nothing you paste or upload is sent to our server.

Want to go the other way? The JavaScript Transpiler compiles modern syntax back down for older browsers.