Методы написания новой строки в JavaScript

Чтобы написать новую строку в JavaScript, вы можете использовать следующие методы:

  1. Метод 1. Использование символа новой строки “\n”:

    console.log("This is the first line.\nThis is the second line.");
  2. Метод 2. Использование литералов шаблона (ES6):

    console.log(`This is the first line.
    This is the second line.`);
  3. Метод 3. Использование тега разрыва строки в HTML:

    console.log("This is the first line.<br>This is the second line.");
  4. Метод 4. Использование метода String.fromCharCode():

    console.log("This is the first line." + String.fromCharCode(10) + "This is the second line.");
  5. Метод 5. Использование метода объединения массива():

    console.log(["This is the first line.", "This is the second line."].join('\n'));