Hi Arun Desai,
There are two types of quote mark in JavaScript, the single-quote (') and double-quote ("). Either can be used to delimit a string literal, or sequence of characters. For example:
myDblQString = "This string is surrounded by double-quote marks.";
mySngQString = 'This string is surrounded by single-quote marks.';
However, since HTML itself makes extensive use of double-quotes within tags, it's a good idea to use single-quotes to set off strings in your scripts. This is particularly useful when your code contains quoted elements, as follows:
onClick = "alert( 'Are you sure?' )";
Strings containing apostrophes, which are identical to single-quotes, require you to use the backslash character (\) to escape the apostrophes, as shown below:
myEscString = 'John didn\'t like Mary\'s hat.';
Quoted strings can be combined with other strings, whether literals or variables:
errMsg = "Passwords are case-sensitive.";
message = "Error: " + errMsg;
// assigns 'Error: Passwords are case-sensitive.' to message
Nov 23, 2009