Using Object.is to compare two values

JavaScript has a complex relationship with equality. It is common knowledge that using === is preferable to == because it gives more predictable results, and in most cases === behaves as expected. Unfortunately, due to quirks in the JavaScript type system, there are some frustrating edge cases.  In this recipe, we'll see how to use Object.is to get expected results for comparisons.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.