Escape characters in JavaScript

JavascriptWeb DevelopmentObject Oriented Programming

Escape characters are characters that can be interpreted in some alternate way then what we intended to. To print these characters as it is, include backslash ‘\’ in front of them. Following are the escape characters in JavaScript −

\fForm Feed
\nNew Line
\rCarriage Return
\tHorizontal Tabulator
\vVertical Tabulator
\'Single quote
\"Double quote

Following is the code implement escape character Backslash in javaScript −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .result {
      font-size: 18px;
      font-weight: 500;
<h1>Escape characters in JavaScript</h1>
<div class="result"></div>
   let str = 'Hello World "This" is some sample \\ Text \' ';
   let resEle = document.querySelector(".result");
   resEle.innerHTML = str;


Updated on 17-Jul-2020 07:12:58