In this section, we will look at the various aspects of working with strings or text-based data.
In this section, we will demonstrate the CoffeeScript feature of string interpolation.
In JavaScript, creating strings that include variable values involves concatenating the various pieces together. Consider the following example:
var lineCount = countLinesInFile('application.log'); var message = "The file has a total of " + lineCount + " lines"; console.log(message);
This can get pretty messy and CoffeeScript provides an elegant solution to avoid this called string interpolation.
CoffeeScript provides the ability to perform string interpolation by using double quoted strings containing one or more #{}
delimiters.
The preceding example can be written as follows:
lineCount = countLinesInFile 'application.log' message = "The file has a total of #{lineCount} lines" console.log message
This not only requires less typing, but it can also...