DEV Community

Rahul Nayak
Rahul Nayak

Posted on

6 3

Front-End-Snippets E01: Is window and document object the same?

For a very long time, the most basic and important Front end web development concepts eluded me and scared me away to a point where I started to skip these concepts and hide my head in the sand. All these concepts came to haunt me later on when I went to web developer interviews. The interviews were an eye-opener and I realized there is so much that I do not know yet.

And this brings me and you to this first post of a larger series where I would share snippets of concepts used in Front end development process. These snippets are short, concise posts that will hopefully get you started with some of the most confusing parts of Front end development.

Starting this series with this week’s topic: Is window and document object the same? If not, how are they different?
Let’s dive in.

Window Object

Window is basically an object which is created when you run JavaScript in a browser.
But what does this window object represent? It represents the current window of the browser. If you open 10 tabs, each tab would have its own window object.

Now let’s see it in action. Open your developer console, type window and hit enter. You’d get something like this:

Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}
Enter fullscreen mode Exit fullscreen mode

Expand the object and you’d find a lot of familiar functions that you use on a more frequent basis like setTimeout or setInterval. The window object shares all of its properties globally which means you do not need to type window.setTimeout to use it. Simply calling setTimeout with the required arguments would do the job.

Now, this window object does not belong to JavaScript, it belongs to the browser so it would contain all the web APIs that you can leverage. Navigation, setTimeout, setInterval, history, audio, video to name a few.

Document

The Document object is one of the properties of a window object. The Document is what renders on the screen. If you crack open the document object, you’d find the entire Html tree that you see on the webpage in the current window.

Open the console again and run window.document and you can see the entire Html tree for the webpage you are on. Here is a screenshot from the dev.to homepage:

output of window.document command in browser console

Pretty neat stuff right! And this is all I have for this post. Tune in for the upcoming posts.

Before I go, shower some love if the post helped you in any way, share the feedback in the comments section and if there are any web development related concepts that should be demystified, let me know and I’ll write about it in the future.

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed
  • 2:34 --only-changed
  • 4:27 --repeat-each
  • 5:15 --forbid-only
  • 5:51 --ui --headed --workers 1

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay