Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Babel still required in 2018? [closed]

I'm learning JavaScript right now and some said that after I learned HTML and CSS and vanilla Javascript I need to have the knowledge about ES6/ES2015. When I watch tutorials on Youtube it says that we need Babel or something like that for the browser to read it. So I'm wondering because that video is not that old (but still old). Is it still necessary to have Babel or I should skip this Babel thing?

like image 435
Alpha_Bords Avatar asked Jan 28 '18 13:01

Alpha_Bords


People also ask

Is Babel necessary anymore?

In 2020, frontend developers are still wasting a lot of time with excessive tooling. Babel is seen by some as a necessity, but I aim to show you that it's not. By the end of this article, you will know: How to confirm which browsers actually need supporting on a case-by-case basis.

Do I need Babel if I use TypeScript?

If you need custom transformations, you'll need to use Babel. The good news is that most TypeScript tools allow you to both use TypeScript and then run the code through Babel afterwards, to get the best of both worlds. But this obviously comes with additional complexity in your build-chain.

Why is Babel needed?

Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backward-compatible version of JavaScript in current and older browsers or environments. Babel's plugins allow you to use the new syntax, right now without waiting for browser support.

What is Babel a transpiler?

Babel is a free and open-source JavaScript transcompiler that is mainly used to convert ECMAScript 2015+ (ES6+) code into a backwards compatible version of JavaScript that can be run by older JavaScript engines. Babel is a popular tool for using the newest features of the JavaScript programming language.


2 Answers

Babel is a JavaScript-to-JavaScript compiler, sometimes called a transpiler, that converts code written with one set of features (for instance, those in ES2015 and later) into code that can be run in a JavaScript environment that doesn't support those features. (There are others, Babel is just one quite popular one.)

Whether you use Babel to transpile your ES2015+ code to ES5 is entirely up to you, and depends on what target environments you want to support. If you want to support any version of IE (including IE11), for instance, you'll need to transpile. If you only need to support cutting-edge Chrome, Firefox, and Edge, or other environments where you can count on the features you're using being there (like up-to-date Node.js installations), you don't.

Kangax has a set of handy tables for what JavaScript engines and/or browsers support which of the more modern features of JavaScript (not just ES2015, but ES2016, ES2017, etc.).

Babel (and tools like it) are useful beyond just using the most-recently-standardized features, in at least two ways:

  1. You can use Babel (and similar) to take advantage of features that are likely to be standardized soon, even though they're not well-supported yet. For example, the basics of public class fields haven't changed in a long time, but the proposal they're in is still (as of this writing in June 2018) at Stage 3 (and has been back and forth between Stage 2 and Stage 3 a couple of times) for reasons unrelated to public class fields, and not even cutting-edge browsers like Chrome, Firefox, and Edge have support for public class fields yet. But it's common, these days, to use class fields via a transpiler.

  2. You can write your own Babel (or similar) transform to add your own features to JavaScript for your own project (or use ones other people have written), even if those features are never going to be part of JavaScript or used outside your project.

like image 155
T.J. Crowder Avatar answered Sep 21 '22 15:09

T.J. Crowder


Not to be off topic--as a beginner I recommend staying away from tooling and configurations. It can be overwhelming, especially in JS land. Just focus on learning, tooling will come later. You can start using ES6 right away without any tooling.

One way is to use an online REPL or playground. One tool I like is https://stackblitz.com this website let's you get a real feel for importing modules from npm to assist your code. If you are on Chrome, you can open the developer console and see the messages you send from the playground to the developer console.

https://developer.chrome.com/devtools

Here is a playground I made to get you started

https://stackblitz.com/edit/react-t3wxth?file=index.js

like image 32
Babakness Avatar answered Sep 19 '22 15:09

Babakness