One of the greatest challenges of building for the Web is the plethora of devices, operating systems and browser combinations that the product must support. How do you move this universal platform forward whilst retaining compatibility with older setups, which often still represent a significant percentage of the market?
At its core, the technology of the Web has evolved quite conservatively over the years — we still have HTTP requests with verbs, headers and body. However, the applications that we build on top of them are as complex as ever, not only on the server, where the complexity of web applications has traditionally lived, but also on the client, with front-end applications handling astonishing amounts of business logic and data access operations.
This paradigm puts additional pressure on the technologies that live in the browser, especially the JavaScript language, to evolve in such a way that gives developers the tools they need to write powerful, concise and performant code. Which brings us back to the opening question: how do you push JavaScript forward whilst retaining compatibility with those browsers whose capabilities are locked in time forever?
Polyfills
ECMAScript 2015 (aka ES6) introduced Number.isNaN, a new and more robust method for determining whether a variable is NaN. Older browsers, such as Internet Explorer, don’t recognize this method and therefore will throw an error when interpreting it.
In this particular case, it’s fairly straightforward to equip legacy browsers with the missing feature. Syntactically, there is nothing in the expression Number.isNaN(x) that legacy systems won’t understand – it’s a case of calling a function that doesn’t exist, so we can simply create it ourselves.
Number.isNaN = Number.isNaN || function
Knowledge
Last Updated:
September 2019

