Struggling with variable interpolation in JavaScript strings. I need to replace the words_to_be_removed variable with the defaultMessageTest string, but none of my attempted methods are working. Here are the three methods I tried:
String text ${expression}
- "String text ${expression}"
- "String text " + expression " String text"
function remove_alert_word(alert_word) {
const words_to_be_removed = [alert_word];
const defaultMessageTest = "Alert word ${words_to_be_removed} removed successfully!";
channel.del({
url: "/json/users/me/alert_words",
data: {alert_words: JSON.stringify(words_to_be_removed)},
success() {
update_alert_word_status(
$t({defaultMessage: defaultMessageTest}),
false,
);
},
error() {
update_alert_word_status($t({defaultMessage: "Error removing alert word!"}), true);
},
});
}