String Methods
Difficulty: easy
Overview
Strings are immutable primitives. Key methods: charAt(i), charCodeAt(i), indexOf(str), includes(str), toUpperCase(), toLowerCase(), substring(start, end), slice(start, end), trim(), trimStart(), trimEnd(), split(separator), replace(), and padStart()/padEnd(). Template literals (backtick syntax) support multi-line strings and embedded expressions via ${}.
Practice Linked Questions
Q1. Which code correctly uses a template literal?
Select one answer before revealing.
Q2. Which string method returns the index of the first occurrence of a substring, or -1 if not found?
Select one answer before revealing.
Q3. What does `" hello ".trim()` return?
Select one answer before revealing.
Q4. What is the output? ```js console.log("JavaScript".substring(0, 4)); ```
Select one answer before revealing.
Q5. What does `"a,b,c".split(",")` return?
Select one answer before revealing.
Q6. What does `"A".charCodeAt(0)` return?
Select one answer before revealing.
Q7. What does `"hello".toUpperCase()` return?
Select one answer before revealing.
Q8. What is the output? ```js const str = "hello world"; console.log(str.includes("world")); ```
Select one answer before revealing.