How To Escape Single & Double Quote In JavaScript

Escape Character Is Used When We Want To Want To Remove Conflict Between Codes Of Two Same Language. For Example , If You Want To Show HTML Code Inside HTML Webpage , Then You Need To Enter Escape Character Instead Of Some Characters Like < > & ' ". In This Post , We Will Learn How To Escape Single As Well As Double Quote In JavaScript


Escape Single Quote In JavaScript

To Escape Single Quote ( ' ) In JavaScript , We Need To Replace ' With \'

Example Code To Escape Single Quote In JavaScript

Unescaped


var abc='Hi There';

Escaped


var abc=\'Hi There\';

Escape Double Quote In JavaScript

To Escape Double Quote ( " ) In JavaScript, We Need To Replace " With \"

Example Code To Escape Single Quote In JavaScript

Unescaped


var abc="Hi There";

Escaped

var abc=\"Hi There\";