1

I wanted to interpolate variables in strings in JS so I used ``(backticks) as shown here - How To Interpolate Variables In String in JS

Then, I Wanted To put IF-Statements in jQuery Append So I got this - IF Statements In jQuery Append

But When I use Both Together , Backticks Don't Output Text As Usual-

$("main").append(`Hello ${my_var}`+(second_var>1?"hi ":"bye")+`Bye ${my_var})`

This Results Only In "hi" , The Backticks Before And After The Ternary Operator Don't Output Anything. HELP ??

LoneWolf47
  • 41
  • 6

1 Answers1

1

You can do something like the below.

const my_var = "Name";
const seconde_var = 2;
console.log(`Hello ${my_var} ${seconde_var >1 ? "hi": "bye"} bye ${my_var}`);
thevarunraja
  • 326
  • 3
  • 8