Date Published: 10 November 2012
The first version will return undefined, while the latter returns a new object with a status of true. I also thought it was interesting that you can actually redefine the global variables for undefined and NaN, as they are not, in fact, constants or reserved words. Crockford writes “That should not be possible, and yet it is. Don’t do it.”
There are many reasons why == is a Bad Part, explained in Appendix B: Bad Parts (along with a number of other Bad Parts). Despite the book’s name, I appreciate these appendices showing me which parts aren’t so good, and why. Finally, Appendix E is devoted to JSON, and includes a fully functional parse utility that avoids the need to use the (not so secure) eval() method.
Steve is an experienced software architect and trainer, focusing currently on ASP.NET Core and Domain-Driven Design.