Javatpoint Logo
Javatpoint Logo

JavaScript Special Characters

JavaScript allows us to add special characters to a text String using a backslash (\) sign. We can add different types of special characters, including the single quote, double quote, ampersand, new line, tab, backspace, form feed, etc., using the backslash just before the characters.

The following is the list of the characters that can be added to a string in JavaScript:

Name Special Character
Single quote \'
Double quote \"
Ampersand \&
Newline \n
Tab \t
Backslash \\
Carries return \r
Backspace \b
Form feed \f
Vertical tab \v

Before diving into how to add special characters in a string, let's understand what the strings are in JavaScript.

JavaScript String

In JavaScript, a String is a sequence of characters, symbols, and numbers. A String contains a few characters, symbols, and even numbers. For example, "abc", "abc@!#", and "abc@12345".

The String is one of the most used data types in any programming language. Like other data types, String takes its memory allocation, and in TestComplete, Strings are represented as OLE-compatible variants.

The Strings are recognized as a sequence of characters enclosed in a matching pair of quotation marks. The quotation marks could be either single (') or double ("); both are treated equally and considered as having a String value.

The following are some examples of some valid Strings:

The String object is available for all supported scripting languages so that users can operate and use string values regardless of the chosen language.

Let's understand how to insert special characters into a String:

Insert Special Characters to a String in JavaScript

We can add special characters to a String by using a backslash (\) symbol. We can insert different types of special characters, such as apostrophes, new lines, quotes, and other special characters.

Consider the below example:

Let's see another example:


The String is 12 character(s) long.

Thus, We can insert any special characters in our String text.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA