Interpolation in React is not working this way can anybody please help me in this regards?

Viewed 59

I am trying interpolation, this way

var sample = "test";
var result = 'this is just a ${sample}'; 
alert(result);                         

it's not working, it's just alerting as it is, this is just a ${sample}, can anybody please help me regarding this? Thanks

2 Answers

You need to use backticks instead of quotes (which are left of the 1 on your keyboard)

var result = `this is just a ${sample}`; 

With ES5, it would be

var sample = "test";

var result = 'this is just a '+sample; 

alert(result);                             
Related