Introduction
In this blog, you are going to learn how JavaScript built-in methods work internally. You will also learn how developers make JavaScript compatible with older browsers using polyfills.
What are polyfills :
A polyfill is a piece of JavaScript code that adds support for modern features in older browsers that don’t support them natively.
If the browser doesn’t have a feature, we create it ourselves.
Example :
Let's take an example that older browser doesn't support Array.prototype.includes.
We write polyfill like this
if (!Array.prototype.includes) {
Array.prototype.includes = function (value) {
for (let i = 0; i < this.length; i++) {
if (this[i] === value) {
return true;
}
}
return false;
};
}
What are Built-in methods?
Built-in methods are predefined functions provided by the JavaScript runtime environment that are used to perform specific tasks. We don’t need to write the logic from scratch.…