LearnFrenzy
Sign in Take a free test

Strings · JavaScript Strings MCQ · Question 5

slice vs substring with negative numbers Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

For const s = "Hello";, what are s.slice(-3) and s.substring(-3)?

  • A "llo" and "llo"
  • B "Hel" and "Hello"
  • C "llo" and "Hello" Correct
  • D "Hello" and "llo"
Correct Answer: Option C

slice counts negative indexes from the end; substring treats negatives as 0, so it returns the whole string.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links