Lokendra Verma
Lokendra Verma

Reputation: 21

Logging just length in console returns 1

I logged (length) in console and it returned 1. Generally javascript compiler would throw an error like "length is not defined" but here it returned 1, is there any relevance of this default value of length ?

> console.log(length)

  Output: 1

Upvotes: 0

Views: 34

Answers (1)

Roko C. Buljan
Roko C. Buljan

Reputation: 206459

window.length returns the number of frames

Read more about Window.length on MDN

Returns the number of frames (either <frame> or <iframe> elements) in the window.

On a (blank) page without such elements it's expected to return 0, here on this exact StackOverflow page you might expect something like 2

To get more info you might want to use window.frames

Also from the MDN Docs Window.frames:

Window.frames Returns the window itself, which is an array-like object, listing the direct sub-frames of the current window.

Upvotes: 4

Related Questions