String literals are specified by using either double quotes (“) or single quotes (‘). This differs from Java,
where double quotes are used to specify strings and single quotes are used to specify characters. However,
because ECMAScript has no character type, it is permissible to use either notation. For example, the follow-
ing two lines are valid:
var sColor1 = “blue”;
var sColor2 = ‘blue’;
The string type also encompasses several character literals, which should be very familiar to Java, C, and
Perl developers. The following table lists the ECMAScript character literals:
A character represented by octal code
octal digit 0-7)
A character represented by hexadecimal code
is a hexadecimal digit 0-F)
A Unicode character represented by hexadecimal code
nnnn (where n is a hexadecimal digit 0-F)
One of the most important features of any programming language is the capability to convert between
types, and ECMAScript provides developers with a number of easy conversion routines. Most types
contain methods that provide for simple conversion, and several global methods are available for more
complex conversion. In either case, type conversion is a short, one-step process in ECMAScript.
he l l o !
The string "hello!" has a length of 6.
05_579088 ch02.qxd 3/28/05 11:35 AM Page 21