alert(str.substring(0, 4)); // would print "Java"
alert(str.substr(0, 4)); // this will also return "Java"
Though this code also returns Java, but here logic is different, as here starting index is zero and length of substring is 4, which means four characters long string, which starts from first character, that's why "Java". If we apply different argument we will get different result e.g.
alert(str.substr(4, 6)); // this will return Script
alert(str.substring(4, 6)); // this will return "Sc"