In CoffeeScript, the following statement evaluates to a JavaScript statement that is prefixed by an empty string.
I feel like there is an edge case with regards to type safety, but I can't think of it off the top of my head. In what case does the prefix make a difference?
CoffeeScript:
x = "#{foo} bar"
JavaScript:
x = "" + foo + " bar";
{a:'y'}+" thing"=> NaN but""+{a:'y'}+" thing"=> "[object Object] thing". So my guess is that concatenating an object to an empty string callstoStringon the object before concatenation+operator's definition and ensures concatenation (7) vs. addition (8). A contrived example is"#{3}#{4}". With the empty string at the start of the expression ("" + 3 + 4), it results in"34". Without it (3 + 4), the result is7.{a:'y';}being block syntax (see these questions). Try({a:'y'})+" thing"{}adds some additional complexity since they have 2 uses in JavaScript. When written on its own,{} + " bar"is actually two statements,{};and+" bar";, with a block and unary+. The parenthesis Bergi mentioned make it an Expression and the{}anObjectliteral.({}) + " bar"results in"[object Object] bar".