return multiple template literals Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of return multiple template literals without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Is it possible to return multiple template literals?

Like this:

wrapperClass() {
  return 
    `masonry--${masonryData.direction}`,
    `masonry--${masonryData.theme}`
  };
}

Answer

Is it possible to return multiple template literals?

No, not as two separate strings that aren’t part of some other object.

You get to return ONE value. That value can be a string, an array, any type of object or any other primitive. You cannot return two strings without putting them into an array or an object.

Here are some of your options:

// return a two element array
wrapperClass() {
  return [
    `masonry--${masonryData.direction}`,
    `masonry--${masonryData.theme}`
  ];
}

// return an object with two properties
wrapperClass() {
  return {
    direction: `masonry--${masonryData.direction}`,
    theme: `masonry--${masonryData.theme}`
  };
}

With either of these options, you can call the function and then, from the return value, you can extract either of your two strings.

We are here to answer your question about return multiple template literals - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji