Search code examples
javascriptsyntaxtags

Why Math.sin`1` works and Math.sin'1' not


If I enter this expression in the browser console (with grave accent):

Math.sin`1`

It will return:

0.8414709848078965

But if I enter this expression (with single quote):

Math.sin'1'

It will throw this error:

SyntaxError: Unexpected number

Why does this error happen?


Solution

  • tag`template literal` is specifically part of the template literal syntax. It doesn’t work for other string literals.