9.11 More String Details
There are two forms for strings—string primitives and string objects. A string primitive is simply a group of characters. String primitives are also known as string literals, and they are written with single quotes (as in ‘Carpe Diem!’) or double quotes (as in “Let’s not seize the day—let’s have a meeting instead!”). A string object wraps up a string primitive, and in doing so, it adds properties and methods. In this section, we’ll introduce one string property and several string methods.
A string object’s length
property returns the number of characters in the string. Note this example, which uses the length property:
var musician = "Taylor Swift"; alert("There are " + musician.length + " characters in \"" + musician ...
Get Web Programming with HTML5, CSS, and JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.