Due to the fact that JavaScript APIs have their own specifications, not all the browsers support a particular specification at the same time.
A JavaScript API can be implemented in a browser sooner or later than the other browsers.
Because of that, we have to provide a patch version of API to make sure that it still works on browsers that don't support it natively. That kind of patch is called polyfill.
The following sample code provides a patch for the `startsWith`
method which doesn't override the API if it exists:
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString) {
};
}
If we provide a polyfill as a library, then we can use the following approach:
const startsWithPolyfill = function (searchString) {
};
const startsWith = String.prototype.startsWith || startsWithPolyfill;
export default startsWith;