Working with Strings
Like numbers
, strings
are simple immutable data types that are managed within the JavaScript runtime as a list of binary values, which are representable as characters. Since they are immutable, they cannot be altered. If you modify a string
, using one of the various methods provided, you are actually creating a new string with the changes applied.
The literal representation of strings is a list of characters surrounded by quotes. These quotes can be double quotes, single quotes (apostrophes), or backticks:
console.log( "I am a string" ); console.log( 'I am also a string' ); console.log( `I am a special string` );
Strings can be thought of as a long list of single characters, much like arrays, which will be discussed later. As such, it is possible to query individual, or groups of, characters:
["H", "e", "l", "l", "o", ",", " ", "W", "o"...