Escape dollar sign in JavaScript template literals (template strings)

The only case where $ does not produce the literal $ is before a {, otherwise you do not need to escape it.

var response = `You have $${money}`

does work therefore. In case you need to escape anything, the backslash \ is the escape character in template strings as well, so (while unnecessary) the following works as well:

var response = `You have \$${money}`

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)