Skip to content Skip to sidebar Skip to footer

Redefinition Of Length?

When I try to create a variable named length var length = 10; JSLint complaints Redefinition of 'length'. var length = 10; But where does that length come from? Fiddle

Solution 1:

window already has length defined:

window.length : Window Object

Solution 2:

If you had, say, an array:

howlong=myarray.length;

would return the number of elements in the array.

If you had a string:

howlong=mystring.length;

would return the number of characters in the string.

Long story short, 'length' is used all over the place. Most useful.

Post a Comment for "Redefinition Of Length?"