var alpha = "ABCDEFG";
var result = alpha.substring(0, 5);
document.write(result);
The question is, why the answer is ABCDE(0,4) instead of ABCDEF (0,5). All numbers in programming start with zero, right?
var alpha = "ABCDEFG";
var result = alpha.substring(0, 5);
document.write(result);
The question is, why the answer is ABCDE(0,4) instead of ABCDEF (0,5). All numbers in programming start with zero, right?
String.prototype.substring takes up to two arguments. One for the start index one for the end index (optional). While the starting index is included in the new string, the end index is excluded. When 4 is the end index that character will be excluded and you will see characters 0-3
Please read https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring