JavaScript > Placing JavaScript code

Special characters in JavaScript

How to display special characters in JavaScript?


Following are the list of characters that can be used to show the special characters to the users.

  • \’ – shows single quote character
  • \” – shows double quote character
  • \& - shows ampersand character
  • \\ - shows double back slash
  • \n – shows new line
  • \t – shows tab
Here we are using "\" (Back slash) as escape characters (escape character is used to override the following character default behavior) to display special characters.
<script>
 function AlertMe() {
    alert("\"This sentence has a double quote \", being displayed using escape character.!");
 }
</script>

<input type="button" id="btnAlert" onclick="AlertMe()" value="Show Alert" />

In the above code, alert will show (double quotes) character in the alert message that is being displayed by using the escape character “\”.

OUTPUT

 Views: 1077 | Post Order: 8



Write for us