Categories
JavaScript Answers

How to fix unexpected string concatenation with JavaScript?

Spread the love

Sometimes, we want to fix unexpected string concatenation with JavaScript.

In this article, we’ll look at how to fix unexpected string concatenation with JavaScript.

How to fix unexpected string concatenation with JavaScript?

To fix unexpected string concatenation with JavaScript, we can use template literals.

For instance, we write

const ANR = "Animal Friend,ANR,ANP,$30";
const specialityPlates = [
  {
    cName: "Environmental",
    oSubMenu: [
      {
        cName: `${ANR}`,
        cReturn: `${ANR}|27.00`,
      },
    ],
  },
];

to put the ANR into the template literal to return a string with ANR‘s content in it.

Conclusion

To fix unexpected string concatenation with JavaScript, we can use template literals.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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