var country = "Kingdom of Morocco";
document.write("<p>The country name contains " + country.length + " characters.</p>");
document.write("The name has "+myname.length+" characters.");
var str1 = "abc"
var str2 = "a b c"
var str3 = "\"abc\""
document.write(str1.length + "<BR>")
document.write(str2.length + "<BR>")
The output of this script is:
The index of a string’s last character is equal to its length (number of characters) minus one. The string’s length is the index of the nonexistent character following the string’s last character.