cover

String Interpolation #

String interpolation allow us to easily concat variable and some strings easily.

You can surely write and js code without string interpolation but it will make you life simpler.

  • The code become easily to understand.
  • No need to use unwanted + for string concatenation.
  • Life become easier when we have more variables to concat with some string.

Let me show you how world will look like without string interpolation and how it will make a significant difference.

world-without-this.js
let num = 21;
let result = "Square of " + num + " is " + num * num + ".";
print(result);

Let’s now use the string interpolation and see how it is better choice for us as a programmer.

string-interpolation.js
let num = 21;
let result = `Square of ${num} is ${num * num}`;
print(result);
comments powered by Disqus