ES6: Create Strings using Template Literals

A new feature of ES6 is the template literal. This is a special type of string that makes creating complex strings easier.

Template literals allow you to create multi-line strings and to use string interpolation features to create strings.

Consider the code below:

const person = {
name: "Zodiac Hasbro",
age: 56

// Template literal with multi-line and string interpolation
const greeting = `Hello, my name is ${person.name}!
I am ${person.age} years old.`;

console.log(greeting); // prints
// Hello, my name is Zodiac Hasbro!
// I am 56 years old.

A lot of things happened there.

Firstly, the example uses backticks (`), not quotes ('or "), to wrap the string.

Secondly, notice that the string is multi-line, both in the code and the output. This saves inserting within strings.

The ${variable}syntax used above is a placeholder. Basically, you won’t have to use concatenation with the +operator anymore. To add variables to strings, you just drop the variable in a template string and wrap it with ${and }. Similarly, you can include other expressions in your string literal, for example ${a + b}.

This new way of creating strings gives you more flexibility to create robust strings.

Use template literal syntax with backticks to display each entry of the resultobject’s failurearray. Each entry should be wrapped inside an lielement with the class attribute text-warning, and listed within the resultDisplayArray.


const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["id-blacklist", "no-dup-keys"]
function makeList(arr) {
  "use strict";

  // change code below this line
   const resultDisplayArray =[];
   arr.map((x) =>{return resultDisplayArray.push(`<li class="text-warning">${x}</li>`);});
  // change code above this line

  return resultDisplayArray;
 * makeList(result.failure) should return:
 * [ `<li class="text-warning">no-var</li>`,
 *   `<li class="text-warning">var-on-top</li>`, 
 *   `<li class="text-warning">linebreak</li>` ]
const resultDisplayArray = makeList(result.failure);

Definition – What does Web Programming mean?

Web programming refers to the writing, markup and coding involved in Web development, which includes Web content, Web client and server scripting and network security. The most common languages used for Web programming are XML, HTML, JavaScript, CSS and PHP. Web programming is different from just programming, which requires interdisciplinary knowledge on the application area, client and server scripting, and database technology.

At some point most web developers will be in the position of having to either provide hosting for their clients’ websites, or they will need to know which web hosts to recommend to their clients. Web hosting services store and activate all the files your website needs in order to function and to be active. Some of the best web hosting companies are: HostGator, GoDaddy, Bluehost, iPage, InMotion Hosting, HostFav, DreamHost, Interserver, Namecheap, 1 & 1, Fasthosts, Hostinger, GreenGeeks, Justhost, SiteGround, Host1Plus, eUKhost, Arvixe, FatCow, HostMonster and more.

Web Programming Degree

If you have a passion for connecting people through technology, our online Web Programming degree will provide you with in-demand skills to do so in a growing industry. In our program, you’ll become proficient in Java, Microsoft Azure, Google Developers Training, Web development and cloud computing—all of which help you prepare for various types of web programming roles, such as web developer, front-end developer, back-end developer or web app developer.

Through online Web Development courses, you’ll build your own professional portfolio for your future employers.


Leave a Reply

Your email address will not be published. Required fields are marked *



7 + 1 =