Algorithm
-
Declare a Variable:
- Declare a variable to store the multiline string.
-
Use Template Literals:
- Utilize template literals (enclosed by backticks ``) for multiline strings.
- Break lines within the template literal as needed.
Code Examples
#1 Code Example- Create Multiline Strings Using +
Code -
Javascript Programming
// program to create a multiline strings
// using the + operator
const message = 'This is a long message\n' +
'that spans across multiple lines\n' +
'in the code.'
console.log(message);
Copy The Code &
Try With Live Editor
Output
This is a long message
that spans across multiple lines
in the code.
that spans across multiple lines
in the code.
#2 Code Example- Create Multiline Strings Using \
Code -
Javascript Programming
// program to create a multiline strings
// using the \ operator
const message = 'This is a long message\n \
that spans across multiple lines\n \
in the code.'
console.log(message);
Copy The Code &
Try With Live Editor
Output
This is a long message
that spans across multiple lines
in the code.
that spans across multiple lines
in the code.
#3 Code Example- Create Multiline Strings Using Template Literal
Code -
Javascript Programming
// program to create a multiline strings
// using the template literal
const message = `This is a long message
that spans across multiple lines
in the code.`
console.log(message);
Copy The Code &
Try With Live Editor
Output
This is a long message
that spans across multiple lines
in the code.
that spans across multiple lines
in the code.
Demonstration
JavaScript Programing Example to Create Multiline Strings-DevsEnv