JS Coercion Tool

This tool will try to show you what happens when javascript applies coercion rules for regular equality comparison (==). It is in fact the depiction of the Abstract Equality Comparison Algorithm (11.9.3) in ES5.

JS is notorious for these coercion rules. They allow for some disturbing outcomes when comparing two variables of different types. For example, an object is always true when you apply !! to it. An array is an object (always). However, comparing an empty array to true results in false ([]==true = false). This tool will show you that the array is converted to a string (for arrays, that's the same as .join(','), resulting in empty string). The string is converted to number (the conversion of empty string is explicitly stated to be zero). The boolean value is converted to a number, true becomes 1. Clearly, 0!=1. This is just one of many examples. I hope this tool will shed some light on what's actually going on.

Created by Peter van der Zee, November 2010, see blog post.

Change anything to see the steps taken.
You can set the toString and valueOf settings yourself for "Object".
They are set correctly automatically for the built-in object instances.
Does not work in IE below 9.