Strings
EasyIn plain terms
Strings are text, created with quotes or backticks. Template literals allow embedded expressions. Many methods: length, slice, indexOf, includes, replace, split, toUpperCase.
What you need to know
- •Single, double, backtick quotes
- •Template literals ${}
- •Immutable - methods return new string
Try it yourself
Copy the code below and run it in your browser console or a code editor:
const s1 = 'Hello';
const s2 = "World";
const s3 = `Hello, ${name}!`; // template literal
s1.length; // 5
s1.slice(1, 4); // "ell"
s1.indexOf('l'); // 2
s1.includes('ell'); // true
s1.replace('l', 'L'); // "HeLlo"
s1.split(''); // ['H','e','l','l','o']
s1.toUpperCase(); // "HELLO"
`2 + 2 = ${2 + 2}`; // "2 + 2 = 4"Learn more
Dive deeper with these trusted resources: