How to do String Interpolation with JavaScript | CampusHippo
String interpolation is a really useful programming language feature that allows you to inject variables directly into a string.
Until the release of ES6, string interpolation was not available in JavaScript. The lack of this feature has lead to horrifying concatenated code that looks like this:
function crazyString(something, someone, somewhere) { return someone + " was looking for " + something + " in the general vicinity of " + somewhere; }
What's the wrong with this? It is difficult to read and understand, especially when the function grow more complex. No developer wants to maintain a bunch of data that is frankenstein'd together to make a human readable sentence. You have to keep track of all the white space between each string, which is easy to overlook. At no fault of their own, many developers have been forced to write JavaScript like this because JavaScript simply lacks string interpolation.
Read full article from How to do String Interpolation with JavaScript | CampusHippo
No comments:
Post a Comment