Escape Characters

Using backslashes to escape characters.

Examples

Escaping Quotes

Using backslash to include double quotes inside a double-quoted string.

let text = "We are the so-called \"Vikings\" from the north.";
console.log(text);

New Line

Using \n to create a line break (visible in alert/console).

let text = "Hello\nWorld!";
alert(text);

Backslash

Escaping the backslash character itself.

let path = "C:\\Users\\Admin";
console.log(path);

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.