Due to a bug in the Tumblr theme editor, any time the sequence \n
appears in the source code, it is converted to an actual line break in the source code itself. Therefore, putting the \n
sequence into a Javascript string causes the program to crash, as it breaks the string into multiple lines.
I was wondering if there is another way to notate the newline character in JavaScript, which could allow me to work around this issue.
The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.
The newline character ( \n ) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen.
The \r metacharacter matches carriage return characters.
Wow, that's an ugly bug.
Yes, you can use \u000a
instead (or \u000A
). It's the Unicode escape sequence for the same character. (Or worse case: String.fromCharCode(10)
.)
Gratuitous example:
console.log("\n" === "\u000a"); // true
console.log("\n" === "\u000A"); // true
console.log("\n" === String.fromCharCode(10)); // true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With