polyfill
A polyfill is code that adds a missing standard feature to an older JavaScript engine by implementing it in plain JavaScript, so programs can call the standard API whether or not the engine ships it natively.
Web developer Remy Sharp coined the word around 2009, after Polyfilla, a British paste for filling cracks in walls. A polyfill first checks whether the feature already exists, a step called feature detection, and installs its own version only when it’s missing. Code written against the standard then runs unchanged, and engines that already ship the feature keep their faster native version.
Polyfills usually target Array methods, Promise helpers, and other built-ins that a newer ECMAScript edition added. The core-js library collects polyfills for most ECMAScript built-ins. A polyfill can only add values and functions, though. New syntax such as optional chaining makes an older engine fail with a SyntaxError before any code runs, so it needs transpilation instead.
Some features can’t be polyfilled at all. Proxy and WeakRef depend on engine internals, and BigInt changes how operators behave. The kind of missing feature decides the fix:
Example
Consider a scoreboard that reads the latest score with .at(), a method added in ES2022, on an engine that predates it. The program deletes the native method to stand in for that engine, then installs a polyfill:
at-polyfill.mjs
delete Array.prototype.at;
console.log(`Native .at(): ${typeof Array.prototype.at}`);
if (!Array.prototype.at) {
Object.defineProperty(Array.prototype, "at", {
value: function at(index) {
const offset = Math.trunc(index) || 0;
return this[offset < 0 ? this.length + offset : offset];
},
writable: true,
configurable: true,
});
}
const scores = [10, 20, 30];
console.log(`Latest score: ${scores.at(-1)}`);
Running the file shows the method missing and then working:
$ node at-polyfill.mjs
Native .at(): undefined
Latest score: 30
The if check is the feature detection, so the polyfill runs only when .at() is missing. Defining the method with Object.defineProperty() keeps it non-enumerable like the native one, so it doesn’t show up in a for...in loop. This version is simplified and skips some steps the spec defines, such as its range check.
Related Resources
Tutorial
Latest Node Version: Node 26 LTS and When to Upgrade
The latest Node version is Node.js 26 LTS. See what changed, what breaks when you leave Node 22 or 24, and how the new yearly calendar works.
For additional information on related topics, take a look at the following resources:
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 21, 2026