Getting the Length of a String
The length property returns the length of the string, which is the number of characters contained in the string. This includes the number of special characters as well, such as
var str1 = "This is a paragraph of text."; document.write(str1.length); // Prints 28 var str2 = "This is a \n paragraph of text."; document.write(str2.length); // Prints 30, because \n is only one character
length is a property, not a function, so don’t use parentheses after it like
str.length(). Instead just write
str.length, otherwise it will produce an error.