André Bargull (2014-08-26T16:27:26.000Z)
> Claude Pache wrote:
> >/  Personally, I use the following expression in order to coerce a variable to a string:
> />/
> />/  	var obj = this + ''
> />/
> />/  and its in-place variant:
> />/
> />/  	x += ''
> />/
> />/  I think it'll continue to work in ES6.
> /
> Agreed, this is the correct-and-most-concise way to do it. It should
> throw on symbols, that's important.
>
> Having String(sym) not throw is a win for other reasons Arv identified,
> but using String(any) to invoke ToString is verbose and fragile, because
> String could be rebound :-P. Use +'' if you want ToString in the
> language, I say.
>
> /be

If `x` is an object, x + '' performs ToString(ToPrimitive(x, <no 
hint>)), whereas String(x) performs ToString(ToPrimitive(x, hint 
String)). So both expressions are not always interchangeable.


- André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140826/07d08639/attachment.html>
domenic at domenicdenicola.com (2014-09-08T23:26:04.083Z)
If `x` is an object, `x + ''` performs ToString(ToPrimitive(x, <no hint>)), whereas `String(x)` performs ToString(ToPrimitive(x, hint String)). So both expressions are not always interchangeable.