Predict String slice Output
Predict Output Medium
Question
What does this code print?
Code
const text = "JavaScript";
console.log(text.slice(0, 4));
Hint
slice(start, end) extracts from start up to (but not including) end.
Explanation
slice(0, 4) extracts characters from index 0 up to (but not including) index 4. "JavaScript" characters at indices 0-3 are J-a-v-a, giving "Java". The end index is exclusive.
Related Resources
Related Lessons
- Strings and Text
Learn how strings and text work in programming.
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.