Loading lessons...
String Basics
String Basics
A string is a sequence of characters like letters, numbers, and symbols.
Writing strings
You can use single quotes, double quotes, or backticks:
let a = "Hello";
let b = 'Hello';
let c = `Hello`;
All three create the same string.
String length
let text = "Hello";
text.length; // 5
Access characters
text[0]; // "H"
text.charAt(1); // "e"
Concatenation
Join strings with +:
"Hello " + "World"; // "Hello World"
Escaping quotes
Use a backslash to put quotes inside a string:
let msg = "She said \"Hi\"";
Common escapes
\nnewline\ttab\\backslash\"and\'quotes
TL;DR
- Strings are text wrapped in ', ", or `.
.lengthgives the number of characters.+joins strings.- Backslash escapes special characters.