- A sequence containing some letters, numbers or symbols.
- Have available methods and properties.
- Can be stored in variables.
- Sit between either single quotes (
' '), double quotes (
" "), or backticks (
- Can be concatenated (stuck together) with the
+operator, or with backticks (template strings) in ES6.
- Can contain special characters, such as quotation marks, as long as they are escaped - e.g.
"She'\ll be coming '\round the mountain when she comes".
- There's no need to escape dissimilar quote marks. For example: "This 'is' fine". This is probably why we tend to favour double quotes in HTML attribute values, and singles in JS (since it allows you to create some innerHTML without the need for escaping).
- When using template literals, you don't need to escape
this` `"is"` `'also'` `fine
- Is either a string primitive - immutable and more common, e.g.
const stringPrimitive = "Hello, I am a string.";.
- Or a string object -
const stringObject = new String("Hello, I am a string.");
typeofoperator is used to determine if a string's type is string or object.
- Each character is indexed and can be accessed by an index number using square bracket notation (e.g. "Hello World" -
- Similar methods to the one above include:
- Other common methods and properties are:
Many thanks to my good friend Mark for suggesting additions :)