When I use the console.log()
method with a template literal and I interpolate the expression 5 + 5 within ${}
, the result is not given in the console.
This is my code:
<script>
console.log('five plus five is ${5 + 5}');
</script>
When I check the console, it just repeats, "five plus five is ${5 + 5}
" without the quotes, of course.
What am I doing wrong?
Thanks! (=
You are using the wrong "quotes" ... use the back-tick `
You can only use template literals with backticks.
Learn more about Template Literals at MDN
Wrap it inside back tick (`) character not inside single(
'
) or double quotes"
, See template literals