In addition to all the above, one should note that, for a defined value v
:
String(v)
calls v.toString()
'' + v
calls v.valueOf()
prior to any other type castSo we could do something like:
var mixin = {
valueOf: function () { return false },
toString: function () { return 'true' }
};
mixin === false; // false
mixin == false; // true
'' + mixin; // "false"
String(mixin) // "true"
Tested in FF 34.0 and Node 0.10