Strings are declared by placing the characters between a pair of double quotes (" ") or single quotes ('').
JavaScript interprets single quotes as part of the string if the single quotes are inside a pair of double quotes.
JavaScript interprets double quotes as part of the string if the double quotes are inside a pair of single quotes.
Or, you will you need to use escape sequences.
Syntax to create String object
var variable = new String(string);
"string"
The String() object is one of the core JavaScript objects.
Instances are created when a program constructs an instance using the new keyword and passing it the String() object.
Properties and Methods Used by the String Object
Method/PropertyDescription
anchor()Creates an instance of the tag with the NAME attribute set to the string passed to the method.
big()Converts the string into an instance of the tag.
blink()Converts the string into an instance of the tag.
bold()Converts the string into an instance of the tag.
charAt()Returns the character at the index passed to the method.
charCodeAt()Returns the ISO-Latin-1 number of the character at the index passed to the method.
concat()Concatenates the two strings passed to return a new string. This method was added in JavaScript 1.2.
fixed()Converts the string into an instance of the , fixed pitch font tag.
fontcolor()Sets the COLOR attribute of an instance of the tag.
fontsize()Sets the SIZE attribute of an instance of the tag.
fromCharCode()Returns the string value of the ISO-Latin-1 number passed to the method.
indexOf()Returns the index of the first occurrence of the string passed to the method within an instance of a String object.
italics()Converts the string into an instance of the tag.
lastIndexOf()Returns the index of the last occurrence of the string passed to the method within an instance of a String object.
link()Converts the string into an instance of the tag and sets the HREF attribute with the URL that is passed to the method.
match()Returns an array containing the matches found based on the regular expression passed to the method.
replace()Performs a search and replace, using the regular expression and replace string passed to the method, on the instance of a String that calls it.
search()Returns the index location of the match found in the string passed to the method. A -1 is returned if the string is not found.
slice()Returns the string between the beginning and ending index passed to the method. If a negative number is passed, the index is referenced from the end of the string passed.
small()Converts the string into an instance of the tag.
split()Returns the string split into segments defined by the string and instance limit passed to the method.
strike()Converts the string into an instance of the tag.
sub()Converts the string into an instance of the tag.
substr()Returns the string beginning with the indexed location and number of characters to return. If a negative number is passed, the index is referenced from the end of the string passed.
substring()Returns the string between the beginning and ending index passed to the method.
sup()Converts the string into an instance of the tag.
toLowerCase()Converts all the characters in the string to lowercase.
toSource()Returns the string representation of the String passed.
toString()Returns the characters passed as type string.
toUpperCase()Converts all the characters in the string to uppercase.
lengthReturns the length of the string.
prototypeProvides the ability for a programmer to add properties to instances of the String object.
Examples of the String Object