ES6 Template Strings

| Page Views: 37 es6

Template Strings were introduced in ES 6 and allows us to:

  1. Perform strings concatenation without the + operators.
  2. Insert variables into a string.

Before we were used to concatenating strings using the + or , operators:

console.log(lastName + ", " + firstName + " " + middleName)

However with template strings we can insert variable values into our srings using the ${}:

console.log(`${lastName}, ${firstName} ${middleName}`)

Between the ${} you can add any Javascript expression that returns a value.

Template Strings preserve the whitespaces making it convenient for displaying things like code samples.

With template strings, our statement can span multiple lines of code.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section.

About Me.

After completing his Software Engineering bachelors program, Oclemy(Clement Ochieng) these days is a man of two lives. At day he works for a startup in Nairobi, Kenya. At night he works tirelessly on building ProgrammingWizards TV, a tv channel for student coders and this website to help share the source code. In between he practices Meditation and Self actualization to help him keep balance. He also likes going for long solo walks to connect more with nature.


What do You Think

Previous Post