Redefinition of length?

2019-09-08 06:21发布

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

标签: javascript
2条回答
Juvenile、少年°
2楼-- · 2019-09-08 07:03

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.

查看更多
家丑人穷心不美
3楼-- · 2019-09-08 07:18

window already has length defined:

window.length : Window Object

查看更多
登录 后发表回答