Strings became available in core Javascript 1.0, and were enhanced in Navigator 3.
new String(value) has been used to construct a new string since Javascript 1.1.
The only property that strings have is length (since Javascript 1.0, ECMA-262).
Comparison operators can be used on string values.
The concatenation operator (+) concatenates two string values together, returning another string that is the union of the two operand strings.
"horse " + "and " + "carriage" returns the string "horse and carriage".
There is also a shorthand form:
samplestring = "dog"
samplestring += "sled"
results in samplestring containing "dogsled".
You can play around with strings, changing their colour, makeing them bold, or italicised, or uppercase, or lowercase, or a variety of other things. You can also take a string that has been made bold, for example, then make it italic, or change it's colour, etc.
Here's the body of the javascript from the <head>:
var first = "This is the first string, intended to be bold."
var second = "This is the second string, intended to be italicised."
var third = "This is the third string, intended to be uppercase."
var fourth = "This is the fourth string, intended to be green. Then a copy is made italic too. Then a copy of that is made uppercase."
// change the look of the strings
var first_bold = first.bold();
var second_italic = second.italics();
var third_upper = third.toUpperCase();
var fourth_green = fourth.fontcolor('green');
var fifth_green_italic = fourth_green.italics();
var sixth_green_italic_upper = fifth_green_italic.toUpperCase();
The strings are then simply written out using document.writeln in the body.
Adds an HTML anchor to a string.
Makes a string <BIG>.
Makes a string <BLINK>.
Makes a string bold with <B>.
Gets the nth character from a string. Javascript 1.0; ECMA-262.
Gets the nth character code from a string. Javascript 1.2; ECMA-262.
Concatenates strings. Javascript 1.2.
Makes a string fixed-width<TT>.
Sets a string's colour with <FONT>.
Sets a string's font size with <FONT>.
Searches a string. Javascript 1.0; ECMA-262.
Makes a string italic with <I>.
Searches a string backwards. Javascript 1.0; ECMA-262.
Adds a hypertext link to a string.
Finds one or more regular expression matches. Javascript 1.2.
Replaces substring(s) matching a regular expression. Javascript 1.2.
Searches for a regular expression. Javascript 1.2.
Extracts a substring. Javascript 1.2.
Makes a string <SMALL>.
Breaks a string into an array of strings. Javascript 1.1; ECMA-262.
Strikes out a string with <STRIKE>.
Makes a string a subscript with <SUB>.
Returns a substring of a string. Javascript 1.0; ECMA-262.
Extract a substring. Javascript 1.2.
Makes a string a superscript with <SUP>.
Converts a string to lowercase. Javascript 1.0; ECMA-262.
Converts a string to uppercase. Javascript 1.0; ECMA-262.
Creates a string from character encodings. Javascript 1.2; ECMA-262.
Back to top Home Serious Stuff
© 2002. Copyright Sue Nethercott.