Go Back   Wiki NewForum | Latest Entertainment News > Career Forum & Tips > Tech Forum & Tutorial > Java Forum & Tutorial


JavaScript Special Characters


Reply
Views: 2121  
Thread Tools Rate Thread
  #1  
Old 05-03-2009, 05:42 PM
welcomewiki welcomewiki is offline
Member
 
Join Date: Dec 2008
Location: India
Posts: 80,538
Default JavaScript Special Characters

In JavaScript you can add special characters to a text string by using the backslash sign.
Insert Special Characters

The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.


Look at the following JavaScript code:


var txt="We are the so-called "Vikings" from the north.";
document.write(txt);

In JavaScript, a string is started and stopped with either single or double quotes. This means that the string above will be chopped to: We are the so-called


To solve this problem, you must place a backslash (\) before each double quote in "Viking". This turns each double quote into a string literal:


var txt="We are the so-called \"Vikings\" from the north.";
document.write(txt);

JavaScript will now output the proper text string: We are the so-called "Vikings" from the north.

Here is another example:


document.write ("You \& I are singing!");

The example above will produce the following output:
You & I are singing!

Reply With Quote
Reply

New topics in Java Forum & Tutorial





Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
WikiNewForum)