February 2006
Intermediate to advanced
826 pages
63h 42m
English
Strings are enclosed by either single (') or double (") quotes and can contain zero or more characters:
var empty = '';
var girl_cat = 'Sabine';
var boy_cat = "Dakota";
var zip_code = '06517';Your string can also contain quotes, but you need to be careful to escape any quotes that match the quotes you are using to enclose your string:
var my_string = 'This "quoted text" is fine';
my_string = "This 'quoted text' is fine";
my_string = 'This string\'s "quote" is escaped';
my_string = "This string's \"quotes\" are escaped';It can get a little confusing if you don’t maintain some form of consistency. Most JavaScript developers tend to use single quotes to wrap strings . This is likely a holdover from other languages where double-quoted strings are processed differently than single-quoted ones.
Read now
Unlock full access