Multiple choice technology enterprise content management

var test = 'Hello World' what will test.slice(3,-1) result in.

  1. Compilation Error, Postive value expected.

  2. Runtime Error, Postive value expected

  3. lo world

  4. lo worl

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The slice(start, end) method extracts up to but not including end. A negative index counts from the end of the string. For "Hello World" (length 11), -1 refers to 'd'. Slicing from 3 to 10 yields "lo Worl".