For both current stable jQuery versions (1.11.0 & 2.1.0), I've noticed that jQuery.length == 2
after jQuery is loaded.
Why is that ?
Both jQuery[0]
and jQuery[1]
are undefined.
I'm familliar with the jQuery array-like objects and console behavior regarding arrays/objects and objects with .length and .splice().
Just wondering about jQuery.length
jQuery
is a function, and the length
property of a function equals the number of formal (declared) parameters to the function. From MDN:
length
is a property of a function object, and indicates how many arguments the function expects, i.e. the number of formal parameters. This number does not include the rest parameter. By contrast,arguments.length
is local to a function and provides the number of arguments actually passed to the function.
Specifically, the jQuery
function has this signature (source):
jQuery = function( selector, context ) {
...
}
jQuery
is a function.
The length
property of a function returns the number of declared parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With