Sometimes we need to print a character that has a special meaning in JavaScript, but we just want to use it the normal way - as a literal character.
Some characters that have special meaning are
We talked about quoting previously, so you know we can use the back-tick quote ` if you have a string containing both double and single quote characters.
But if we haven't used the back-tick, we have to escape the special character with a back-slash:
Sprint('<br/>This string has an apostrophe right here \', escaped with the back-slash.<br/>');
Escaping a character means to render it without it's intended meaning.
Here is a back-tick:
Sprint('\`</p>');
Sprint('<p>What is 35 \\ 9?</p>');
Yes, that's the wrong character for division, but it does say it correctly 😎.
Coders sometimes want to break up a long line of code into separate lines. We can do that.
Three ways are available for that:
let Title =
"The Title of This Book Is: Something I Forgot To Do Last Night";
let Title = "The Title " +
"of This Book Is: " +
"Something I Forgot " +
"To Do Last Night";
use template strings (wrapped in back-ticks)
let Title = `The Title
of This Book Is:
Something I Forgot
To Do Last Night`;