Babel Explained: Writing Tomorrow's JavaScript Today
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"] } 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. That targeting is the whole point — you ship the smallest transformation necessary, not a blanket do...