There are certain characters that we can't simply type in a string. For example, a line break (when you press the Enter key and start a new line). Line breaks are a character themselves, but we can't just press Enter in the middle of a single-quote or double-quote string.
See what happens if we try to include a line break inside a string:
"This line break
will cause an error"
We need to add the line break another way.
Strings created with backticks can include line breaks. Backticks create a special kind of string. Remember how we can only do interpolation when we are using backticks?
`This line break
will be included in the string.`
Did you notice the output of the last example? It was a little strange:
"This line break\nwill be included in the string."
Instead of a line break, we see
\n in the string. This is an escaped character.
Common Escape Codes
Below are some examples of common characters and how to escape them:
|Line break (new line)