Menu

Babel Explained: Writing Tomorrow's JavaScript Today
📰

Babel Explained: Writing Tomorrow's JavaScript Today

DEV Community: javascript·The Practical Developer·about 3 hours ago
#j4fUcUlB
#devtojavascript#devto#dev#syntax#babel
Reading 0:00
15s threshold

Introduction

JavaScript evolves every year — optional chaining, nullish coalescing, private fields — but browsers and users don't upgrade on your schedule. Babel bridges that gap: it is a compiler that takes modern JavaScript and transforms it into an older version that virtually any browser can run, so developers write the newest syntax without abandoning users on older devices.

Presets and plugins: transformation in layers

Babel works through plugins, each transforming one syntax feature, grouped into presets for convenience:

{ "presets" : [ "@babel/preset-env" ] }

Enter fullscreen mode

Exit fullscreen mode

preset-env is the smart one: tell it which browsers you support (via a browserslist query like "last 2 versions"), and it transforms only the features those browsers lack. A browser that already supports optional chaining keeps it untouched; an older one gets the longer equivalent code.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.