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.

let num = 21;
let result = "Square of " + num + " is " + num * num + ".";

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

let num = 21;
let result = `Square of ${num} is ${num * num}`;
comments powered by Disqus