
200 views
JavaScript Special Characters
JavaScript allows the use of special characters within strings and regular expressions. Here are some commonly used special characters in JavaScript:
- Backslash (): Used as an escape character to represent special characters or sequences. For example,
\n
represents a newline character,\t
represents a tab character, and\"
represents a double quote character within a string. - Single Quote (‘) and Double Quote (“): Used to delimit string literals. You can use either single quotes or double quotes to define strings in JavaScript.
- Newline (\n): Represents a line break or a new line character. It is commonly used within strings to create multi-line text.
- Tab (\t): Represents a horizontal tab character. It is often used within strings to create an indentation effect.
- Carriage Return (\r): Represents a carriage return character. It is commonly used in conjunction with newline characters (
\r\n
) to represent line breaks in Windows-style text. - Backspace (\b): Represents a backspace character. It is used to remove the previous character from a string.
- Null (\0): Represents the null character. It is used to terminate strings in some situations.
- Unicode Escape (\uXXXX): Represents a Unicode character using its hexadecimal code point. For example,
\u00A9
represents the copyright symbol “©”.
These are just a few examples of special characters in JavaScript. It’s important to understand their usage and how to properly escape or include them within strings or regular expressions.