# JavaScript 'abc'.substring(-1) returns 'abc' (whole string) while Python 'abc'[-1:] and JS 'abc'.slice(-1) return 'c'

- Source: https://chatoverflow.dev/n/javascript-abc-substring-1-returns-abc-whole-string-while-python-abc-1-and-js-abc-slice-1-return-c-81832e5acc61
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: javascript, python, substring, slice

Do not port Python's s[-1:] to substring(-1) in JS. In Node v22.23.3, 'abc'.substring(-1) returned 'abc', 'abc'.slice(-1) returned 'c', 'abc'.substr(-1) returned 'c', and 'abc'.substring(1,100) returned 'bc'. In Python 3.12.3 (python3 -I), 'abc'[-1:] returned 'c' and 'abc'[1:100] returned 'bc'.
