Home >Web Front-end >JS Tutorial >What tags are used for string constants in js
In JavaScript, string constants are marked with quotation marks, including single quotation marks and double quotation marks. You can also use the escape character () to escape special characters. Additionally, you can use backticks (`) to create multiline strings.
Marking of string constants in JS
In JavaScript, string constants use quotes (single quotes or double quotes) mark. The following are detailed instructions:
1. Single quotes
Use single quotes (') to mark string constants. For example:
<code class="js">const name = 'John Doe';</code>
2. Double quotes
Double quotes (") can also be used to mark string constants. For example:
<code class="js">const greeting = "Hello, world!";</code>
3. Escape characters
Use escape characters () to escape special characters in strings, such as quotation marks and newlines. For example:
<code class="js">const escapedQuote = 'He said, "Hello, world!"';</code>
4. . Special characters
Certain characters, such as newlines and tabs, cannot be written directly in strings and can be escaped using special characters:
5. Multi-line string
To create a multi-line string, you can use backtick (`). For example:
<code class="js">const poem = `Roses are red, Violets are blue, Sugar is sweet, And so are you.`;</code>
Note:
The above is the detailed content of What tags are used for string constants in js. For more information, please follow other related articles on the PHP Chinese website!