var myString = "This is a string";There are times when you actually want to use the quotation mark as part of the string. The following would be wrong as the first quote is interpreted to end before the character s.
var myWrongString = "This is a "string"";
You can get around this by using a single quote.
var myString = 'This is a "string"';Single quotes can have problems when used in conjunction with apostrophe as it will terminate early.
var myString = 'This is Phil's "string"';
var myString = "This is a \"string\"";
\t tab \n new line \" double quote " \' single quote \\ backslash itself
var myString = "hello"; alert(myString.length); // should print 5There are many helpful methods that allow you to manipulate strings. You should look at w3schools for its exact usage.
concat() --- Joins strings and returns a copy of the joined string indexOf() --- Returns the position of the first occurrence of a specified value in a string lastIndexOf() -- Returns the position of the last occurrence of a specified value in a string repeat() -- Returns a new string with a specified number of copies of the string it was called on replace() -- Searches for a match between a substring and a string, and replaces the substring with a new substring split() -- Splits a string into an array of substrings, and returns the new array substr() -- Extracts a substring from a string, beginning at a specified start position, and through the specified number of characters toLowerCase() -- Converts a string to lowercase letters toUpperCase() -- Converts a string to uppercase lettersJust to give you some idea of how to use it...
var s1 = "The quick brown fox"; var s2 = "jumps over the lazy dog"; var newstring = s1.concat(s2); // alert(s1.indexOf('fox')); // 16 alert(s1.indexOf('cat')); // -1 not found