String Slice
Predict Output Easy
Question
What does this code print?
Code
console.log("hello".slice(1, 3));
Hint
slice(from, to) extracts from index 1 to 3 (exclusive).
Explanation
slice(1, 3) extracts characters from index 1 up to (but not including) index 3. "hello"[1] is "e", "hello"[2] is "l", so the result is "el". Negative indices count from the end.
Related Resources
Related Lessons
- Data Types
Learn JS data types.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.