How to Fix the ESLint ‘Unexpected string concatenation’ Error?

Sometimes, we may run into the ‘unexpected string concatenation’ error when we’re using ESLint to lint our JavaScript project.

In this article, we’ll look at how to fix the ‘unexpected string concatenation’ error when we’re using ESLint to lint our JavaScript project.

Fix the ESLint ‘Unexpected string concatenation’ Error

To fix the ‘unexpected string concatenation’ error when we’re using ESLint to lint our JavaScript project, we should use template literals instead of string concatenation.

For instance, we write:

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

to interpolate the value of the ANR variable into the template string.

Therefore, cReturn is 'Animal Friend,ANR,ANP,$30|27.00'.

Conclusion

To fix the ‘unexpected string concatenation’ error when we’re using ESLint to lint our JavaScript project, we should use template literals instead of string concatenation.