Polyfill
Полифил
A polyfill is code that supplies a feature missing from a browser or another runtime. It lets an application use the standard API even when the runtime does not provide it natively.
What problem does a polyfill solve?
A browser can understand a line of JavaScript perfectly well and still fail when it runs it. Take items.at(-1): the browser knows how to call a method, but an older version may not have Array.prototype.at. Without that method, the call throws a TypeError. A polyfill supplies the missing method so the application can keep using the standard API instead of checking the browser at every call site.
How it works
A polyfill builds the missing behavior using features the target runtime already supports. One common approach is to install a method on a built-in object or its prototype. The installation code typically uses feature detection rather than browser names or version strings. A presence check may be enough for a missing method, but it won't catch a native implementation that returns the wrong result for some inputs. A polyfill may test that behavior too. Either way, the replacement has to be installed before any code that depends on it runs.
Example: adding Array.prototype.at
With core-js installed, an application can import the specific polyfill at its entry point:
import 'core-js/es/array/at';
var colors = ['red', 'blue'];
console.log(colors.at(-1)); // blue
This is a side-effect import: it doesn't give the application a local function to call. It runs code that can install at on Array.prototype, so the usual method call works. If the target browser can't handle JavaScript modules, the build needs to deliver this code in a format it can load.
Polyfill vs. transpilation vs. fallback
A transpiler rewrites source code. For instance, it can turn user?.name into an expression that checks whether user is null or undefined. That helps an older engine parse and run the expression, but it doesn't create missing APIs such as Promise or Array.prototype.at. Conversely, adding a polyfill can't teach the engine to parse newer syntax. Build tools can coordinate both steps, which is why they're easy to confuse.
A fallback takes a different path instead of providing the same API. For example, an app can keep its online experience usable in browsers without service workers. A page script can't recreate the browser's service worker lifecycle or grant itself the same ability to intercept requests.
In production and in interviews
Start with the browsers and versions the product actually supports. Shipping a blanket set of polyfills can add download and startup costs even for users who don't need them. Test the built app in the oldest supported environments: a correct polyfill won't help if it loads after a dependency tries to use the API.
A common interview question is why an app still fails on Promise after being transpiled. Explain that Promise is a runtime API, not syntax, then check whether the build includes a polyfill for the target browser and runs it early enough.