Polyfill in JS explained

Hi FCC users. I have used some of built-in functions like isNaN(). That will look like this:

console.log(isNaN({})); //returns true

But I have a question.

Let’s say that the Number.isNaN() function has a hidden code that looks like this:

Number.isNaN = Number.isNaN || function isNaN(input) {
    return typeof input === 'number' and isNaN(input);

Or the isNaN() function has a hidden code that looks like this:

var isNaN = function (value) {
    var n = Number(value);
    return n !== n;

Are these supposed to be a polyfill? And what is a polyfill??

Please answer.


Hey @pummarinbest,

Polyfill is simply filling in a feature that exists in the newer javascript versions but doesn’t exist in the older browser. So basically you’re the one making the function that exists in newer Javascript but might not exist in the older browsers just in case you need the function. Polyfill is just filling in holes to a feature that you might need but the older browsers don’t support it. Here’s an MDN article that can explain it better than me:

Hope this helps.