Polyfills: add JavaScript features in older browsers if it do not support modern features

JavaScript is a high-level, interpreted scripting language and is widely used in HTML and the Web.
Browsers such as Google Chrome, Mozilla Firefox, Internet Explorer, Safari etc all have most of the standard features including their own proprietary features.
Though the standard of scripting languages like JavaScript is ECMAScript but have cross-browser compatibility issues.

It might be possible that modern browsers supports feather that older not support.
To add the feature in older browser if it do not support polyfill is a piece of code that provides a feature and makes the browser compitable.

The startsWith() is a case sensitive method that determines whether a string begins with the characters of a specified string.
This method returns true if the string begins with the characters else false.

Internet explorer does not support this method.
To make this fature available in IE you can implement as below:

if (!String.prototype.startsWith) {
    String.prototype.startsWith = function (searchString, position) {
        position = position || 0;
        return this.substr(position, searchString.length) === searchString;

Example: 2:
Array.prototype.contains = function (element) {
    return this.indexOf(element) > -1;
Keep visiting this page for more examples.

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments