WXR WXR - 1 year ago 101
Javascript Question

string templates not working - js

I am learning how template strings works with es2015 but somehow the output I get is not what is expected but I don't see what I did wrong.

Can someone please give me a hand?

function buildUser(first, last){
let fullName = '${first} ${last}';

return { first, last, fullName };

let b = buildUser("Talyer", "Willams");

What I get back is an object which is expected but the object returns

first: Talyer
last: Willams
fullName: ${first} ${last}

why am I getting
${first} ${last}
? Shouldn't I get something like
Talyer Willams

Answer Source

You need to be using a backtick not a single quote

let fullName = '${first} ${last}';

should be

let fullName = `${first} ${last}`;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download