String Interpolation

Anyone who writes a lot of JavaScript is very familiar with the way of building strings.

var verb = "mash";
var operators = "plus symbols";
"You " + verb + " them " together using " + operators + "."

This style leaves a little to be desired. One flaw is that it overloads the + operator, and leads to subtle bugs when combining strings and integers. It's easy to overlook the fact that 1 + 2 + "3" will behave differently than "3" + 2 + 1. The other flaw with building strings in JavaScript is that it quickly becomes difficult to read. You find yourself spending time corralling spaces and quote marks just to make sure your string turns out like you are expecting. It's especially painful anytime you find yourself constructing HTML ...

Get CoffeeScript Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.