EN
JavaScript - string newline character
10 points
In this short article, we would like to answer what is the newline character symbol in string in JavaScript.
Quick solution:
Use
\n
as a newline character.
xxxxxxxxxx
1
const text = '123\n456\n789'; // \n used as newline character
2
3
console.log(text); // 123
4
// 456
5
// 789
Notes:
- JavaScript newline character is platform independed,
- but, when we work on a text recived from the outside (people create content, application exchange data with endpoints), we need to know what newline character was used or use some techniques do deal with that text - check this article or go to See also section in the below.