Skip to content

JS String Escape Characters

Syntax

Escape characters in JavaScript are used with a backslash (\) to include special characters within a string.

let escapedString = "He said, \"Hello!\""; // Escapes double quotes
let newLine = "First Line\nSecond Line"; // Adds a newline
let tabbed = "Column1\tColumn2"; // Adds a tab space

Example

let message = "She asked, \"How are you?\"\nHe replied, \"I\'m fine.\"";
console.log(message);
let path = "C:\\Program Files\\App";
console.log(path); // Outputs: C:\Program Files\App