top of page

Babel 101: Writing Future JavaScript, Today

  • Chandan Rajpurohit
  • Apr 21
  • 2 min read

If you’ve spent any time in the JavaScript ecosystem, you’ve likely heard the name Babel come up again and again. It’s one of those tools that quietly powers a huge portion of the modern web, yet many developers use it without fully understanding what it does or why it matters. Let’s break it down in a clear, practical way.


Babel is a JavaScript compiler - a tool that converts modern JavaScript code (ES6+ and beyond) into a version that older browsers or environments can understand.


Why Do We Even Need Babel?


JavaScript evolves quickly. New features - like arrow functions, classes, optional chaining, and async/await - make code cleaner and more powerful. But there’s a catch:

Not all browsers support the latest JavaScript features.

For example, older browsers (like Internet Explorer or outdated mobile browsers) don’t understand newer syntax. If you write modern JavaScript and run it there, your code may break.

This is where Babel steps in.


What Babel Actually Does


Babel takes your modern JavaScript and transforms it into backward-compatible code.


Example:

Modern JavaScript (ES6+)

const greet = (name) => `Hello, ${name}`;

After Babel (ES5)

var greet = function(name) {
  return "Hello, " + name;
};

Same functionality—just rewritten in a way older browsers understand.


How Babel Works (Behind the Scenes)


Babel processes your code in three main steps:


1. Parsing

Your code is converted into an Abstract Syntax Tree (AST), which is basically a structured representation of your code.


2. Transformation

Babel applies plugins to modify the AST. These plugins define how the code should change.


3. Code Generation

The transformed AST is converted back into JavaScript code.


Key Concepts in Babel


1. Presets

Presets are collections of plugins bundled together.


The most common one:

  • @babel/preset-env – Automatically converts modern JavaScript based on target browsers.


2. Plugins

Plugins allow you to transform specific features.


Examples:

  • Transform arrow functions

  • Convert class syntax

  • Support optional chaining


3. Polyfills

Some JavaScript features (like Promise or Array.includes) can’t just be rewritten - they need actual implementations.


Polyfills fill in those missing features.


Real-World Use Case


Imagine you're building a web app using modern syntax like:


  • async/await

  • Optional chaining (?.)

  • Nullish coalescing (??)


Without Babel, your app might break in older browsers.


With Babel:


  • Your code works everywhere

  • You don’t have to worry about compatibility issues


Babel in the Tooling Ecosystem


Babel is rarely used alone. It integrates with many popular tools:

  • Webpack - Uses Babel via babel-loader

  • Vite - Uses Babel internally (or alternatives like esbuild)

  • React - JSX is transformed using Babel

  • Next.js - Comes with Babel configured out of the box


Babel is one of the invisible heroes of modern web development. It allows developers to write cutting-edge JavaScript today while ensuring that their code still runs smoothly across a wide range of environments.


If you're building anything for the web, chances are Babel is already part of your toolchain - even if you didn’t realize it.


Understanding how it works gives you more control, better debugging skills, and the ability to optimize your build process when needed.


In simple terms:👉 Babel lets you write tomorrow’s JavaScript and run it today. Want to know more check out the official website: - https://babeljs.io/

Recent Posts

See All
Difference between json and jsonb in PostgreSQL

PostgreSQL allows to store JSON data in json and jsonb datatype. Let’s understand the difference between json and jsonb. json jsonb json datatype was first introduced with Postgres 9.2. jsonb datatype

 
 
 
Difference between json.dumps() and json.loads()

JSON is important for many backend devs. But sometimes playing with it can be confusing. Being a backend dev or full stack dev you might have written APIs for your Web or Mobile application and I’m su

 
 
 
How to work with DataFrame in Python?

Python language has vast application. Data analysis and manipulation is one of many application. We can work on data using Pandas library in Python for generating data analytics and manipulating data

 
 
 

Comments


bottom of page