Rationale for why ECMAScript converts primitive values to numbers in == operator comparisons when one is boolean

Raymond Plante raymond.plante at gmail.com
Sun Jan 6 13:12:18 PST 2013


Just curious to find out what the motivation for converting both values of
an == operation to integers if one is an integer or a boolean.

This situation allows for:
   if ("true"){}  // to evaluate to true
   if("true" == true){} // to evaluate to false as it's really checking if(
NaN == 1){}

Does anyone know the exact reason the choice was made not to convert to
boolean any value compared against a boolean in with the == operator?


Regards,
Raymond J. Plante

StackOverflow: http://stackoverflow.com/users/722263/ray
LinkedIn: http://www.linkedin.com/in/raymondjplante
Blog: http://www.kineticklink.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130106/887abd74/attachment.html>


More information about the es-discuss mailing list