Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Document Object

The Document interface is a representation of any web page that is open in the browser and serves as an entry point to a web page's content, which is called the DOM tree.

this is what a document object is. I know it is also a property of the global object. Mr. Guil calls it a global object.

A global object is an object that always exists in the global scope. In JavaScript, there is always a global object defined. In a web browser global variables created in scripts are also created in the global object.

Can there be more than one global object? does Mr Guil call the document object a global object because it is always defined in window (the global object )?

1 Answer

Steven Parker
Steven Parker
229,732 Points

You can always create additional global objects, they don't need to be pre-defined to start with. In fact, anything you create outside of a function or code block is global. But the "Window" object is special as the browser lets you access its properties and methods without using the "Window." prefix (like "document" and "alert()").

But modern "best practice" is to keep the scope of things limited to where they are needed. and modular design patterns are created with this in mind.

A global object is an object that always exists in the global scope. In JavaScript, there is always a global object defined.

Im taking the JavaScript and the DOM course and I get very confused when i read the documents that mr guil recommends that we read in the teachers notes. The ones I have read are all MDN docs. for example in the getElementsByTagNames() course my guil says that getElementById() returns an element that can be accessed directly and MDN says The Document method getElementById() returns an Element object representing the element whose id property matches the specified string. What do you think about this should i go with what MDN says or with what mr guil says? you pointed out the MDN also makes mistakes

Steven Parker
Steven Parker
229,732 Points

I trust and promote MDN as my favorite "go-to" reference, what made you think I said otherwise?

But in this case I don't think there's any conflict between the video and MDN. What part do you find confusing?