SPOT THE DIFFERENCE between toString() and + ''.
Posted on 2006-06-17
Can someone tell me what functional difference (if any) there is between these two expressions...
... and ...
obj.func1(x + '');
I'm working on a script that calls functions of an object provided from a separate system. We recently had a problem where the other system was not correctly accepting a value because it was an integer and the function required a string.
They suggested that rather than just pass the variable containing the integer value (x) that we pass x + ''. They had tried it and it worked.
So I adjusted my script using toString() and they said, "No it doesn't work".
So I experimented with this...
var x = 12;
var y = x.toString();
var z = x + '';
alert(y === z);
... and is said "true". Which inclined me to think that the two expressions ARE the same.
So what's going on here? Am I missing something? Or is someone pulling my chain?