Strings in JavaScript are sequences of Unicode (UTF-16) characters.
There isnβt a separate type for representing characters in JavaScript. If you want to represent a single character, use a string consisting of a single character.
Delimiters are single or double quotes:
You can also use template literals, using the backtick character `.
Backtick delimiters are useful for multiline strings and embedded expressions:
You can call methods and properties available in the String
wrapper object directly on a primitive string
value.
The statements above work because JavaScript secretly converts the primitive string
to its wrapper object type String
.
Since ECMAScript 2015, you can access string characters similar to accessing array elements (using square bracket notation):
But you cannot use the square bracket notation to modify the string:
Refer to String
on MDN web docs for more details.