String concatination without +

kdex kdex at kdex.de
Tue May 17 19:48:45 UTC 2016


@Cedric: Your proposed change would break template literals. Consider this example:

```js
const tag = () => 1;
console.log(tag`test`); // Valid syntax, but no way to keep apart tagged template literals from your syntax syntactically
```
Further, with your approach, I don't see a way to take care of proper spacing between the injected variables.
How would you concatenate just two variables, `a` and `b`, without a space in between, without accidentally referencing `ab`?

Lastly, is there any considerable benefit from your proposal, apart from maybe saving a space character in certain cases?
In most real-world use cases, template literals are usually shorter than their `+` equivalent, even if you uglify your whitespace:
```js
const message1 = `Good job, ${user.name}! You've earned ${user.points} with your comment.`;
const message2 = "Good job, " + user.name + "! You've earned " + user.points + " with your comment.";
const message3 = "Good job, "+user.name+"! You've earned "+user.points+" with your comment.";
```

On Dienstag, 17. Mai 2016 19:19:59 CEST Cedric neuland wrote:
> It would be less to write like example below.
> a='a'
> console.log(`b${a}`); //7 chars
> console.log('b'+a); //5 chars
> console.log('b'a); //4 chars -> SyntaxError
> 


More information about the es-discuss mailing list