Learn

We’ve looked up some of the features we used to make our site on caniuse.com and only 75% of internet users can see our content! What do we do? Do we need to rewrite our codebase?

The newer features of JavaScript tend to make it easier to do things rather than add new features, a concept known as syntactic sugar. We can use older syntax to do the same things but it’s usually harder to write.

For example, ES6 added string interpolation, allowing variables and expressions to be incorporated into string content:

`You can make carbonara with ${pasta}, ${meat}, and a sauce made with ${sauce}.`;

The above line can be easily converted to the old syntax by using concatenation instead:

'You can make carbonara with ' + pasta + ',' + meat + ', and a sauce made with ' + sauce + '.';

In order to make our new JavaScript syntax work on old browsers, we need to apply these kinds of transformations. Luckily, tools exist that can automate this process! While compilation translates code from one language to another, transpilation is a term for translating code to different formats of the same language. We can use a transpiler to convert our modern code into a more compatible version.

Before we publish our code online, we take our source code and transpile it. This produces a set of output files that use more browser-compatible syntax. We publish the output files to our web server and can continue to develop our source code with any modern features we want to write!

Instructions

Take a look at the window on the right. The code editor allows you to enter modern JavaScript and see its translation. Try entering some modern JavaScript syntax and see how it can be transpiled!

Scroll to the very bottom and click the up arrow if you can’t see the code editor.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?