Multiline string

2 snippets across 2 stacks - JavaScript, Python

JSJavaScript

Template Literals

JS · Strings
Syntax
`text ${expression} text`
Example
const item = "coffee";
const price = 4.5;
console.log(`One ${item} costs $${price.toFixed(2)}.`);

const multiline = `Line one
Line two
Line three`;
console.log(multiline);
Output
"One coffee costs $4.50."
"Line one\nLine two\nLine three"

Note Backtick strings support embedded expressions and multiline content without escape characters.

PYPython

Multiline Strings

PY · Strings
Syntax
"""text
spanning lines"""
Example
query = """
    SELECT name, email
    FROM users
    WHERE active = true
""".strip()
print(query)
Output
SELECT name, email
    FROM users
    WHERE active = true

Note Triple-quoted strings preserve all whitespace and newlines. Use textwrap.dedent() or .strip() to control leading/trailing space.

Frequently asked questions

How does JavaScript handle multiline string?
This task is covered in 2 stacks on this page: JavaScript, Python. The "Template Literals" snippet in JavaScript uses ``text ${expression} text``.
Which code does the JavaScript example use?
The "Template Literals" snippet uses ``text ${expression} text``, from the Strings section of the JavaScript cheat sheet.
Which stacks cover "multiline string" on this page?
JavaScript, Python. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Template Literals": Backtick strings support embedded expressions and multiline content without escape characters.