Simiilar to the way the Number oblect provides methods for number manipulation, the String object provides methods for string manipulation. As with numbers where you can just let the numbers be converted automatically to Number objects when you need to use the methods, you do the same with text strings.
The \ is used as an escape character and so all \ that actually belong in your text string need to be entered as \\ instead. The main characters you would need to escape in a plain text string are single quotes inside a single quoted string and double quotes inside a double quoted string but there are also a few escape characters to represent new lines, form feeds, tabs etc. that you may also need to use on occasion.
var txt, txt2, txt3;
txt = 'This isn\'t a test.';
txt2 = new String("This also isn't a test");
if (txt.substr(0,4) === txt2.substr(0,4))
txt3 = 'The first four characters are the same.';