The symbol ` what is it for?

hey! how are you? i have two questions. the symbol ` what is it for ? and when do i need to use $ ? thanks!

The accent grave (better known as the back tick) is the syntax that tells JS the string it contains is a string literal that supports variable and expression interpolation.

Consider the following,

a = 6
b = 7
c = `The product of ${a} and ${b} is ${a * b}.`
console.log(c)
// The product of 6 and 7 is 42.

The back ticks are valid quote marks, but are the only ones that can be used with templates.

Note above the ${ }. Those are the interpolation fields of the template literal. Everything else is plain text. Also note that the last field is written as an expression.

2 Likes