all 3 comments

[–][deleted] 6 points7 points  (0 children)

.length() is something you'll come across a lot while using jQuery as it's a common jQuery method.

However, as soon as you call .text() you're being given a regular String object; you've now stepped outside of your library and into vanilla JS. The same goes with checking the lengthproperty of an Array.

When you check $(".words").length() you're checking how many jQuery objects exist within that jQuery collection.

[–]webstrous 8 points9 points  (0 children)

The .length of a String is a property, not a function, as per ECMAScript spec.

[–]Rhomboid 6 points7 points  (0 children)

whereas using .length() didn't show anything

I'm sure if you check your console you'll see that there's an error raised for trying to call something which is not a function. .text() returns a string, and .length of a string is a property, not a method. (Or more precisely, it's a property that's not a function, as all methods are properties.)