The delimiters of your string are '
, so just end the '
, concatenate the icon
, and resume the '
:
const icon = 'myIcon';
const str = '<i class="' + icon + '"></i>';
console.log(str);
But you might find it more readable to use a template literal instead, especially if you're building an HTML string, or if it's multi-line, or if you're having any issues with escape characters: begin and end the string with backticks, and insert variables by putting them inside of ${varNameHere}
:
const icon = 'myIcon';
const icon2 = 'myIcon2';
const icon3 = 'myIcon3';
const str = `
<i class="${icon}"></i>
<i class="${icon2}"></i>
<i class="${icon3}"></i>
`;
console.log(str);