Skip to content
BENIBIX Learn

Escape Character

Development📄 Files & FormatsText

Also known as Escape Sequence, Backslash Escape, Escaping

A mark that changes what the next letter means. Most often it is a backslash.

Think of it like

Think of it like a secret signal to a friend. It says the next word does not mean what it looks like.

Example

Jack writes a Windows path in his code as C:\\Users\\Jack. Each double backslash prints as a single one.

Why it matters

Escaping is how text can hold the characters that would break it. Getting it wrong causes many bugs and some attacks.

Definition

An escape character tells a program to treat the next character in a special way. In most languages it is the backslash. A quote inside text would end the text too soon, so you write \" instead. Some pairs stand for hidden characters, like \n for a new line and \t for a tab. To write a real backslash, you type two of them.

Example code

javascript
console.log("She said \"hi\"\nBye")
// She said "hi"
// Bye
The backslash lets a quote sit inside the text, and it turns n into a new line.
The middle row: a backslash before each inner quote keeps the text in one piece.

Common mistake

Forgetting to escape a quote inside a string. The text ends too soon, and the rest becomes broken code.

Key takeaways

  1. 1
    Changes the next one. The character after it is special.
  2. 2
    Mostly a backslash. Most languages use the backslash.
  3. 3
    Hidden characters. A backslash and n make a new line.

Learn it properly