JavaScript string interpolation works differently.
You can use Template literals, using the backtick ` `.
var bg = 'your-image.jpg';
var ahref = `<a href="#" style="background-image: url('${bg}');"></a>`;
console.log(ahref);
Or you can concatenate strings with the addition operator +.
var bg = 'your-image.jpg';
var ahref = '<a href="#" style="background-image: url(\'' + bg + '\');"></a>';
console.log(ahref);
The url() property does not require quotes, only in certain conditions.
A url, which is a relative or absolute address, or pointer, to the web resource to be included, or a data uri, optionally in single or double quotes. Quotes are required if the URL includes parentheses, whitespace, or quotes, unless these characters are escaped, or if the address includes control characters above 0x7e. source
bgsupposed to be a variable that results in a String of text?'<a href="#" style="background-image: url(\''+bg+'\');"></a>'is foolproof.