JavaScript Special Characters _ Basics

Source: Internet
Author: User

You can use backslashes in JavaScript to add special characters to a text string.

inserting special characters

The backslash is used to insert ellipses, line breaks, quotes, and other special characters in a text string.

Take a look at the following JavaScript code:

"Vikings"From the north. "
document.write (TXT)

In JavaScript, strings start or end with either single or double quotes. This means that the above string will be truncated to: We are the so-called.

To solve this problem, you must precede the quotation mark in "Viking" with a backslash (\). This converts each double quote to a literal string.

\"Vikings\"From the north. "
document.write (TXT)

Now JavaScript can output the correct text string: We are the so-called "Vikings" from the north.

This is another example:

\&Me are singing! ")

The above example produces the following output:

You & Me are singing!

The following table lists the remaining special characters that can be added to a text string using a backslash:

Code Output
\' Single quotation mark
\" Double quotes
\& and number
\\ Back slash
\ n Line feed
\ r return character
\ t Tabs
\b Backspace
\f Page breaks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.