JavaScript type coercion is the set of rules the language follows when
an operator receives a value of a type it did not expect, so it
converts one value into another type before doing the work. When you
write 1 == "1" or [] + {}, the engine does
not guess: it runs a short, published algorithm from the ECMAScript
specification. Coax implements those algorithms
(ToPrimitive, ToNumber,
ToString, ToBoolean, and the Abstract
Equality Comparison) and prints each step so you can read exactly why
a result is what it is.
Coercion is automatic type conversion during an operation. The
+ operator first converts both operands to primitives,
then either concatenates strings or adds numbers. Loose equality
(==) converts across types before comparing.
Boolean(x) maps a value to true or
false. Template literals convert every substitution to a
string. Type two values into Coax to watch each of these run.
=== (strict equality) compares type and value with no
conversion: if the two operands are different types, the answer is
false immediately. == (loose equality)
applies coercion first, which is where the surprising results come
from. Coax traces the coercing operators, == included, so
a == vs === check becomes a question you can
answer by reading the steps rather than memorizing a rule.
Most JavaScript type coercion tables list a fixed set of famous pairs
and their answers. That helps until your bug involves a value the
table never listed, such as an object with a custom
valueOf or a nested array. Coax replaces the static table
with a live one: it computes the result for any pair you enter and
shows the abstract operations behind it, so the coverage is the whole
grammar, not a hand-picked row.
As expressions, both coerce to the string "[object Object]".
The famous difference comes from parsing: at a console statement top
level, a leading {} reads as an empty block, so
{} + [] is actually unary +[], which is
0. Coax evaluates operands as expressions and flags this
exact case, showing both the expression and statement results.
No. Operands are read by a restricted literal parser that never calls
eval or Function. Anything outside the
literal grammar (numbers, strings, booleans, null,
undefined, NaN, Infinity,
arrays, objects) is rejected with an inline error. Everything runs in
your browser and nothing is sent anywhere.