Please note, this is a STATIC archive of website webdevelopmenttutorials.com from 20 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.

Tutorials

Learn web design and programming with our free video and text tutorials.

Web Designer? Design and market your own professional website with easy-to-use tools.

Special Characters in Javascript

Javascript allows you to use special characters such as quotes, apostrophes and new lines to a text string by using the backslash (\) sign.

In JavaScript, a string is started and stopped with either single quotes or double quotes. This causes the javascript below to only display: "And he started with "

<script type="text/javascript" language="javascript">
var txt="And he started with "only time will tell" to begin his speech.";
document.write(txt);
</script>

Javascript allows you to display a special character, in this case the double-quote ("), as part of the text string by placing a backslash (\) in front of the special character.

<script type="text/javascript" language="javascript">
var txt="And he started with \"only time will tell\" to begin his speech.";
document.write(txt);
</script>

The javascript code above display the entire text.

The table below lists The table below lists other special characters that can be added to a text string by using the backslash sign.

character outputs
' single quote
" double quote
& ampersand
\ backslash
n new line
r carriage return
t tab
b backspace
f form feed