Why should we use template literals?

Thanks sir! I’ve roughly grasped the idea and usage of the syntax from your explanation! However, as I’m only a fresh beginner, could you please explain the function of the \ symbol? my assumptions from experimenting with the symbol is that it nulls the functions of other symbol and renders it to be a functionless symbol that could be assigned to a variable. Please guide me on this matter, thank you!

1 Like

In syntax we are given assorted special characters that carry extra meaning to the interpreter. If we wish to use those characters in prose text, we need to tell the interpreter to treat them as printable characters and override their built in role. For that we have escapement given by the escape character, \.

It traces back to word processing and line printers. We needed a way to tell the printer when to print, and when to process a command given in the form of an escape sequence. Embedding these sequences in our text we could tell the printer when to bold text, italicize text, underline text, and so on. That’s history, now, but the principals have remained to this day.

"A quick brown fox jumps over the \"lazy dog\"."

The opening and closing quotes do not print, but the escaped quotes do. It will render like,

A quick brown fox jumps over the "lazy dog".
1 Like

You may want to check out “Kahn Academy” to improve your math skills.

Reading through your example code, it makes a lot of sense. Still a bit complicated but it is starting to make sense. Thank you!

1 Like

You’re the man @mtf. It worked, I can see the potential time-saving.

okay so what im getting from this is that there is no practical reason to use the old single qoutes instead of using the template literals? is that right?

The introduction of template literal syntax did not replace single and double quotes, but added the back ticks as valid quotation marks. We can only write template literals in the new quotes, is all.

Interpolation is superior to concatenation as we quickly discover. Definitely read up on all the cool things we can do with them.

1 Like

I still dont get it. Sorry im abit slow

What is it still don’t get?