oop - What is the significance of the `Object.length` property on JavaScript's `Object` constructor? -
this question has answer here:
the documentation javascript language's built-in global object
object states that
object.length
has value of 1.
what significance of property and, additionally, why isn't object.length
available in same manner array.length
?
at first glance, seem me reason latter question has possible confusion in interpreter of length
property on object dot notation method of property access/initialization.
the
length
property specifies number of arguments expectedfunction
.
as object
belongs type function
, length
property of function determines number of arguments, object.length
returns length of arguments being expected.
consider following example:
function test(a, b, c) {} console.log(test.length);
and object
:
console.log(typeof object); console.log(object.length); //returns 1
"why isn't object.length available in same manner array.length?"
note array
of type object
(try typeof []
) hence "why isn't object.length available us" not literally correct. if referring object-without-indices
, read object property using key
of object
, if there no key length
, obj.length
returns undefined
.
Comments
Post a Comment