easierbycode
3/1/2012 - 10:03 PM

object to primitive coersion

object to primitive coersion

    var foo = { 
        toString: function () { 
            return 5; 
        }, 
        valueOf: function () { 
            return "foo"; 
        } 
    }; 
    alert(foo.toString() + 1); // 6 (bad!) 
    alert(foo + 1);            // "foo1" (no good!) 
    alert(+foo);               // NaN (the worst!)