What's The Issue?
This is why when you write production code you need to rely on tools. ES6 came out quite a while ago now, so the
Babel on its own doesn't do much. To get it to do something meaningful for you, you will need to install some additional presets. To convert ES6 into normal JS, you would configure Babel, like this.
Let us say you have the following script in a file called,
If you run this command in the terminal:
Assuming Babel ran successfully. If you look at your projects file system, you should see that a new file called
output.js has been created. If you look within this file, you will see it contained your converted code. If you were writing production code you wouldn't want to have to manually type in these commands, you would want to use babel with a tool like web-pack, so Babel is automatically run for you. As you can see, babel is a very useful tool to ensure that your code works on all browsers. It's easy to install and get it working, so I would recommend that you give it a try today. Happy Coding 🤘