It might be a stupid question, but why do I get an empty array when I console out Array.prototype
?
I was expecting the push and pop methods.
Because Array is type of object , the fact that an empty Array is conversed to true is correct.
Now we can check if the array is empty by using .length . This will return 0, as there are 0 items in the array.
arrays are objects, objects are truthy. just ask for array. length, if not zero, it will be truthy. when you explicitly convert to Boolean, the array turns into an empty string first, then the empty string turns into false.
Values not on the list of falsy values in JavaScript are called truthy values and include the empty array [] or the empty object {} . This means almost everything evaluates to true in JavaScript — any object and almost all primitive values, everything but the falsy values.
Most of the built-in methods of prototypes are not enumerble, so they won't show up if you use for..in
(which you shouldn't on arrays, but this is just an example). Since they not enumerable, they won't show up if you "console them out".
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