The concatenation is not working for this line of code

40 views Asked by At
let userName = "Kunaal";
let age = 30;

//My name is Kunaal and I am 30 years old//

let text = "My name is ${userName} and I am ${age} years old";
console.log(text);

Expected Output:

My name is Kunaal and I am 30 years old.

Actual Output:

My name is ${userName} and I am ${age} years old.

1

There are 1 answers

2
XMehdi01 On

Use backticks (``) don't use double quotes ("") in your variable text:

Template_literals

In JavaScript, string interpolation is done using backticks (``) and the ${} syntax.

let userName = "Kunaal";
let age = 30;

//My name is Kunaal and I am 30 years old//

let text = `My name is ${userName} and I am ${age} years old`;
console.log(text);