Can someone tell me what functional difference (if any) there is between these two expressions...
obj.func1(x.toString());
... 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.
I thought that was okay, but just thought the + '' looked untidy, and preferred toString() as it makes the code much clearer (strange idea to try and make Javascript clear - I know).
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?
Start Free Trial