Tsallaka zuwa abun ciki
Justice Tech School

slice, substring and substr

slice(start, end) extracts a part and supports negative indexes. substring is similar but swaps arguments if needed. Avoid substr, it is deprecated.

Example
const s = "JavaScript";
console.log(s.slice(0, 4), s.slice(-6), s.substring(4, 10));

Exercise

Take the first 4 characters.

s.slice(0, )

Quiz Test

Which supports negative indexes?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.