Modern JavaScript for React: Template Strings – Part 5

Template Strings is one of the most useful features introduced in modern JavaScript. We have learned Destructuring Object and Arrays in previous posts. Now, let’s go through this.

You can define strings in JavaScript using single quotes (‘ ‘) or double-quotes (” “). These two ways to define strings in JavaScript are equivalent.

Modern ways to define strings, and that’s using the Backtick (“) character. You have to train your eyes a little bit to spot those.

Strings defined in Backtick character are called as Template strings because they can use as a template with dynamics values.

They support what we call interpolation.

You can Inject any dynamic expression in Javascript within dollar curly brackets.

Example of Template String

You can see in the below code we have used div template inside Backtick and inside dollar curly bracket we have defined Math.random function.

  const valMath = `${Math.random()}`;

See the output here in the console window.

We hope you got an idea about this. In the upcoming article, we will deep dive in the Classes in the modern JavaScript.

Subscribe Now!

Subscribe Us For Latest Articles