How to concatenate a variable and string inside a prop in Javascript?

<TextField
          label="First Name"
          defaultValue="My name is" + ${name}
/>

Here, name is the variable storing the actual name. I need to concatenate it with the string “My name is”. $ doesn’t work. I get an error at ‘+’ saying identifier expected.

Answer

Assuming you’re using react, you can use a template literal:

<TextField
  label="First Name"
  defaultValue={`My name is ${name}`}
/>