What does console.log('javascript'.slice(-6, -1)) output?
A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-119.js
1console.log('javascript'.slice(-6,-1))
Coercion
Answer & explanation
Console output
scrip
Why
slice converts negative indices by adding the string length: -6 becomes index 4 and -1 becomes index 9 in "javascript" (length 10). It returns characters from index 4 up to but not including index 9, giving "scrip". The end index is always exclusive, which is why the final "t" is omitted.