Those special characters don’t work in HTML, the literal text ‘rn’ will be rendered in the browser.
Using the backtick ` character creates a Template String, which has a bit more ‘syntactic sugar’ and functionality than raw HTML text. It is a Javascript string and you can use JS special characters (e.g. rn) inside it.
HTML uses character encodings instead, which look like this: . This represents the n ‘newline’ character, and will work in your example.
The former one is pure HTML, i.e. what is between the opening and closing tags will be displayed as is.
<div>{'123rn123'}</div>
Whereas the latter one is JSX, where the inner content is a string (programmatically speaking) – notice the use of {} in the tags – thus r and n being escape characters
2
Answers
Those special characters don’t work in HTML, the literal text ‘rn’ will be rendered in the browser.
Using the backtick
`
character creates a Template String, which has a bit more ‘syntactic sugar’ and functionality than raw HTML text. It is a Javascript string and you can use JS special characters (e.g.rn
) inside it.HTML uses character encodings instead, which look like this:
. This represents then
‘newline’ character, and will work in your example.The former one is pure HTML, i.e. what is between the opening and closing tags will be displayed as is.
Whereas the latter one is JSX, where the inner content is a string (programmatically speaking) – notice the use of {} in the tags – thus
r
andn
being escape characters