String

String

in

A string is a sequence of characters, often represented in memory as an array of bytes. They may contain encoded text, binary data, or formatted data. Strings are a fundamental data type in almost all programming languages.

Formally, strings are a sequence of symbols chosen from a set or alphabet. Fundamental operations on strings include: concatenation, substring, substitution, and sorting by lexicographical ordering. Programming languages such as PHP and JavaScript usually offer all of these functions in their standard library.

In JavaScript, strings are a primitive object, but they get automatically converted to String objects when String methods or properties are called. For example:

var str = "foo";
str.length; // 3
str += "bar"; // concatenation
str.length; // 6
str.indexOf("a"); // 4

the variable str automatically acquires the "magic" property .length as needed, and it is always kept up-to-date. Similarly, the String method .indexOf() is available as needed.

All JavaScript strings can and do contain Unicode characters, and all conversion to and from Unicode is done at the level of the JavaScript engine. To represent a character that is outside the range of ASCII characters in your script, you would typically use the escape sequence \uHHHH with HHHH being the Unicode codepoint in hexadecimal.

Related links

Search Glossary

Term of the Day

A method for submitting data to a web server and a part of the HTTP protocol. This method is typically used instead of GET when the submission is expected to change resources on the server or cause side effects.
See also: HTTP GET