Home > Software design >  jQuery How To Use Backticks In Append
jQuery How To Use Backticks In Append

Time:12-19

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 ??

CodePudding user response:

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}`);

  • Related