Transpiling
Rewrites code syntax, such as arrow functions or optional chaining, for older runtimes.
Transpiling changes syntax. Polyfills add missing APIs. They solve different support problems and should not be confused.
// Transpiling can rewrite syntax. const value = user?.profile?.name ?? "Unknown"; // A polyfill may be needed for missing APIs. Promise.allSettled(tasks);
Versions & Runtimes
When a target environment does not support modern JavaScript, tooling can sometimes help. A transpiler rewrites newer syntax into older syntax. A polyfill provides missing built-in functionality or APIs.
These tools are powerful, but they have limits. Syntax can often be transformed. Browser APIs sometimes need polyfills. Some features cannot be perfectly recreated in older environments.
The goal is not to transpile everything forever. The goal is to support the users you actually need to support with the smallest reliable toolchain.
Rewrites code syntax, such as arrow functions or optional chaining, for older runtimes.
Adds missing functions or objects when an environment does not provide them.
The environment level your final JavaScript is built for.
More compatibility can mean more generated code, larger files and more complexity.
Examples
// New syntax problem: use transpiling.
const title = course?.lesson?.title ?? "Untitled";
// Missing API problem: use a feature check and fallback/polyfill strategy.
if (!("fetch" in window)) {
showUnsupportedBrowserMessage();
}
// Transpiling this syntax does not automatically add every browser API.
const response = await fetch("/api/articles");
// If fetch is missing, transformed syntax is not enough.
Rules that matter
Modern JavaScript is powerful, but support is never automatic. Choose syntax, APIs and tooling based on the environments that must run the code.
Use transpilation when the parser cannot understand modern syntax.
Use polyfills when a built-in object or method is missing and can be safely emulated.
Do not ship large compatibility code to users who do not need it.
Some platform features depend on browser internals and need a fallback instead.
Future developers need to know why the build emits a certain JavaScript level.
Do not only test source code. Test what the browser actually receives.
Production thinking
Understanding the difference prevents expensive confusion. A transpiler cannot invent a full browser platform, and a polyfill does not make unreadable syntax parse.
Compatibility tooling helps users on older or restricted environments, but broken polyfills can also create fragile experiences. Test important interactions.
Production builds should balance compatibility, file size, caching, performance and maintenance burden.
If generated JavaScript fails, rendered content and navigation may fail. Keep critical content and links resilient.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. Versions and runtimes look theoretical until they break a real page.
Senior audit upgrade
Use these references when browser support, syntax details or proposal status matters.