window.length

Most of the time, when dealing with vanilla JavaScript code, I try things out directly in the browser. I just open the console within my favorite developer tools and start poking around until I gain whatever I searched for.
Today I made a small mistake and accidentally called something similar to this:
myVariable - length
And as I hit return on my keyboard, I already saw my foolish mistake. The property access I did was not valid but a calculation with a not defined variable called length
. Then I saw the output:
myVariable - length
-3
What? How did that happen? Did I declare length
by mistake as a variable? Why does it not throw an error? Or - wait for a second - is this available as a property on the window
object?
Yep, window.length
exists. And as I apparently did not know anything about its existence, I asked the best online resource about it - the Mozilla Developer Network web docs.
window.length
Returns the number of frames (either
<frame>
or<iframe>
elements) in the window.
Yes, it exists. Now you know too.
Written by Eric (@thezieger) who is a
Frontend Developer currently working for
Invia Travel Germany GmbH the pan-European market leader in online travel marketing.